472,371 Members | 1,448 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Maintain an uploaded Image in a Session


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

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


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 2112

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

Similar topics

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...
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...
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...
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....
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" %>
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...
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" %>
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...
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...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.