As it is said in the title of this discussion, I am trying to use inputfileID.fileContent twice, here inputfileID = fileAttachment, as following :
If fileAttachment.HasFile Then
Dim sExtension As String = LCase(System.IO.Path.GetExtension(fileAttachment.FileName))
If sExtension = ".pdf" Then
Dim iFileSize As Integer = fileAttachment.ContentLength
Dim attachment As New PdfReader(fileAttachment.FileContent)
Dim iPageCount As Integer = pdfPageCount(fileAttachment.FileContent)
Dim sFilePath As String = System.Configuration.ConfigurationSettings.AppSettings("FILES")
Dim sFileName As String = "attachment_" & Session("pkyUser") & "_" & iLetterID & ".pdf"
If iPageCount <= iAttachmentMaxPageCount AndAlso iPageCount > 0 AndAlso iFileSize <= iAttachmentMaxSize _
AndAlso attachment.IsOpenedWithFullPermissions AndAlso isPdfPageSizeCorrect(attachment) Then
fileAttachment.MoveTo(Path.Combine(sFilePath, sFileName), MoveToOptions.Overwrite)
I don't why but it seems that "attachment" can get a value but not i PageCount. And when I change these 2 lines, it's iPageCount which can have a value but not attachment.
So why ? And what can I do to fix this ?
The 2 lines I am talking about are :
Dim attachment As New PdfReader(fileAttachment.FileContent) (line 1)
Dim iPageCount As Integer = pdfPageCount(fileAttachment.FileContent) (line 2)
No matter what, the first line works as it should but the second never does.
I have been thinking the issue may be because I did not close "fileAttachment" between both lines (flieAttachment.fileContent.close()). But when I do, an error occurs in the second line saying that the fileAttachment is closed.
what should I do ?
Thanks for your help.