473,287 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Maintain an uploaded Image in a Session

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: sa****@vertexcs.com
Nov 17 '05 #1
0 2243

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
Hi all, I want to be able to resize an image that a user has uploaded. I have the image upload working as well as the image resize. When I go to delete the original uploaded file (I want to...
2
by: bissatch | last post by:
Hi, I am trying to write script that is run when a form is submitted. The form contains an image input field and when submitted, the image is uploaded, resized and added as binary information to...
5
by: Brian Lowe | last post by:
My web site accepts uploaded photos and stores them in a SQL table as BLObs so they never touch the filesystem. I have a way to create a thumbnail version of the uploaded image and store that in...
5
by: Dominic | last post by:
My question is about how to maintain view state in mobile ASP.NET across postback / request in a web farm environment. First of all, let's assume the web-farm does NOT use stick-session feature....
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
2
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is...
0
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
14
by: =?Utf-8?B?U2FtdWVs?= | last post by:
Hi, I have a web app that allows others to upload files, and the problem is that if I allow users to upload image files, fake image can be uploaded and cause XSS issues. In the app, I do...
2
by: andrescasta | last post by:
Hello, i have a problem when i try to delete a file that i recently uploaded. To upload, i used the FileUpload, when i receive the file, i save it in a directory inside the virtual application...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.