473,670 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("PhotoF ile") = filePhoto.Poste dFile

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("PhotoF ile")

Dim lfilePhoto As HttpPostedFile = Session("PhotoF ile")

Dim lintFileSize As Integer = lfilePhoto.Cont entLength

Dim lsFileName As String = Right(lfilePhot o.FileName, _

Len(lfilePhoto. FileName) - lfilePhoto.File Name.LastIndexO f("\") - 1)

Dim lsContentType As String = lfilePhoto.Cont entType

Dim lstreamImage As IO.Stream = lfilePhoto.Inpu tStream

Dim lbytePhoto(lint FileSize) As Byte

lstreamImage.Re ad(lbytePhoto, 0, lintFileSize)

Response.Conten tType = lsContentType

Response.Binary Write(lbytePhot o).

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 2283

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

Similar topics

0
2212
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 replace the uploaded file with the new resized version) I get a "file being used by another process" error. I therefore cannot replace the uploaded image with the new thumbnail. How can I get around this???
2
9300
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 a db table. Please note, I am using a PostgreSQL database I have written all the code out below that deals with the submission processing:
5
4868
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 the db too, again without touching metal. I need a way to overlay some text on the image but I'm stuck. All the help I find uses files in the filesystem, and when I try to convert the example to my imagestream model it fails and I can't...
5
5153
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. In other words, different web servers may serve different requests in the SAME session. In non-mobile ASP.NET, my understanding is that the view state information is passed between each client browser and server with every post-back. Even if...
5
2725
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
3990
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 below and of course it's not working properly because my web page which displays the resulting image from the database is not showing the image. I **think** the problem is in my converting the bitmap back to a byte array. If I change my code back...
0
1209
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
2791
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 check image dimension when uploaded so that any fake image that is actually a text file is blocked (user renames a .txt to .gif, e.g.). However, a png file renamed to .gif can contain script that when loaded
2
2493
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 (ASPNET account have full control on it, ). ... try { //Save the image FileUpload1.PostedFile.SaveAs(savepath); <---This work OK. FileUpload1.PostedFile.InputStream.Close();
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8660
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.