This project has moved and is read-only. For the latest updates, please go here.

Tyring to use twice inputfildID.fileContent

May 24, 2011 at 12:33 PM


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" fileAttachment.FileContent.Close() If iPageCount <= iAttachmentMaxPageCount AndAlso iPageCount > 0 AndAlso iFileSize <= iAttachmentMaxSize _ AndAlso attachment.IsOpenedWithFullPermissions AndAlso isPdfPageSizeCorrect(attachment) Then fileAttachment.MoveTo(Path.Combine(sFilePath, sFileName), MoveToOptions.Overwrite) End If 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 ?

Thanks for your help.


May 24, 2011 at 4:48 PM

I should have been more specific. 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 ?
Jun 1, 2011 at 2:01 PM

No suggestions ? :/

Jun 8, 2011 at 12:36 PM

The solution is here :

Thanks to joeaudette!