1
Vote

Tyring to use twice inputfildID.fileContent

description

Hello,

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 ?

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.

comments

joeaudette wrote May 25, 2011 at 6:56 PM

My advice would be to move the file to where you want it before doing, anything with it. When upload completes the file is in a temporary location, depending on configuration it may be down under Wiondows\TEMP.
You should put it where you want it then access it using the system.io classes instead of trying to work with or process the file while NeatUpload is involved.

Hope that helps,
Joe

houak wrote May 26, 2011 at 12:36 PM

I see what you mean but I have to make these tests :

If iPageCount <= iAttachmentMaxPageCount AndAlso iPageCount > 0 AndAlso iFileSize <= iAttachmentMaxSize _
AndAlso attachment.IsOpenedWithFullPermissions AndAlso isPdfPageSizeCorrect(attachment)

before put the file where I want hence the fact to move the file after the declarations of attachment and iPageCount. I need these 2 informations to make the tests... :/

houak wrote May 26, 2011 at 1:19 PM

Is is possible to close the file and then open it again ?

houak wrote Jun 1, 2011 at 1:01 PM

No suggestions ? :/

joeaudette wrote Jun 1, 2011 at 2:25 PM

You can check the file size first, but I still advise move the file and get it out of NeatUpload before further processing.
FileContent is a Stream object, my guess is that when you pass it into the constructor of your pdfReader it reads and then disposes the stream, therefore it can no longer be accessed anymore

houak wrote Jun 1, 2011 at 3:09 PM

Yes, you are right. I just had to change a few lines --'. The tests could have be done later.
Sorry for my later posts and thank you again for thoses advices !