Maintain an uploaded Image in a Session

S

Satish Appasani

Hi:

I have a ASP.NET form with Web layout which I've achieved using panels. In
one of the tab I have a File control to upload Images. When I put a file in
the file control and move to another tab, I am loosing the file in the file
control. So, I am putting the file in a Session:

Session("PhotoFile") = filePhoto.PostedFile

When the user comes back to the tab with the File upload, an Image control
displays the Image from the session. To make this work, I have built another
aspx page with only code to retrieve the Image from the session. To the
Image control in the parent form, I 'm setting it's ImageURL property to
"Image.aspx" (The file which contains code to retrieve the Image from the
session)

Dim lpostedFile As HttpPostedFile = Session("PhotoFile")

Dim lfilePhoto As HttpPostedFile = Session("PhotoFile")

Dim lintFileSize As Integer = lfilePhoto.ContentLength

Dim lsFileName As String = Right(lfilePhoto.FileName, _

Len(lfilePhoto.FileName) - lfilePhoto.FileName.LastIndexOf("\") - 1)

Dim lsContentType As String = lfilePhoto.ContentType

Dim lstreamImage As IO.Stream = lfilePhoto.InputStream

Dim lbytePhoto(lintFileSize) As Byte

lstreamImage.Read(lbytePhoto, 0, lintFileSize)

Response.ContentType = lsContentType

Response.BinaryWrite(lbytePhoto).



This works fine when I come back to the Image tab for the first time. The
Image control displays the uploaded Image. But If I refresh the page or go
to another tab and return back, the Image is not displayed. When I debug,
all the varibales display correct values which means there is no problem
with the Session.

I have worked around this by Saving the uploaded file to the server and
setting the Image's ImageURL property to the file. This works but I don't
want to do this as the site will be used globally and over the time this
will affect other resources like disk space. Can somebody please help me
with this.

Also, I've a report where I retrieve the Images from the database and
display them on the web page. As this report is too customized, I've to
build the page by dynamically generating HTML using the script. How can I
display each Image from the database on the page? Trying to save the Image
in the file system and then putting in to the HTML is going to be very very
expensive on the file system. Or generating the Image in a separate aspx
page and setting src of the Image to the aspx file will display the last
retrieved Image by Image.aspx for all the Images in the report. Please
provide me a solution for this too...

The last thing I can do is, as this site is an Intranet site and needs
authentication for the users, create a directory for the session in the
server and put all the Image files used by the user in to the directory.
When the session ends, delete the directory. But there should be a better
solution for this.

Thanks in advance.

--


Thank you.

Satish Appasani
#201, Wing - 1, Block - D
Cyber Gateway
Hyderabad - 500 081, India
Phone: +91(40)2311-1356 Ext-122
Mobile: +91(40)333-31032
E-mail: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top