Click here to Skip to main content
14,937,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,

I m Working on a C# Project.
I want to store image in session, which is selected from File Upload control of asp.net & retrieve that image from session & then upload to server side folder.
How can I achieve it ?

Thanks & Regards,

Gulam Hussain
Posted
v2
Comments
   
I don't understand why you need to store image in session ?
Can you please elaborate the reason of doing so ?
Vani Kulkarni 17-Jul-12 2:40am
   
Exactly. What is the reason of storing the image in a session and then retrieve to upload to server side folder?
gmhussain007 17-Jul-12 2:51am
   
bcz i m working on website in which use can upload product image using facebook login id.when user use facebook login id then we call facebook api to check login id & Password Of Use & verify them.after that i create user session for that website.problem occurred when user select login through facebook i lost image path Or image after checking user details.
gmhussain007 17-Jul-12 2:51am
   
bcz i m working on website in which use can upload product image using facebook login id.when user use facebook login id then we call facebook api to check login id & Password Of Use & verify them.after that i create user session for that website.problem occurred when user select login through facebook i lost image path Or image after checking user details.
Yatin chauhan 17-Jul-12 2:41am
   
Why you want to add the image in Session.???
gmhussain007 17-Jul-12 3:08am
   
bcz i m working on website in which use can upload product image using facebook login id.when user use facebook login id then we call facebook api to check login id & Password Of Use & verify them.after that i create user session for that website.problem occurred when user select login through facebook i lost image path Or image after checking user details.

If you have the rquirement to add a image in a session then add the image path in that session and retrieve where ever you want like this.

Session["UploadImage"]=imagepath;
Or
Session["ImageObj"]= ImageObj;
   
Comments
gmhussain007 17-Jul-12 2:55am
   
can we get image in session using java script ?
Rajesh Varma Buddaraju 20-Jul-12 7:44am
   
From javascript it is not possible. From .net we can store the image object in to a session.
It's not a good idea to store the whole image in a session variable. It will use a lot of memory unnecessary. You should save it to disk first and then store the saved image path in a session variable.

C#
var savedFilePath = @"c:\file.jpg";
fileUpload.PostedFile.SaveAs(savedFilePath);
Session["SavedFilePath"] = savedFilePath;
   
Comments
gmhussain007 17-Jul-12 3:27am
   
how can i upload image & store image path into session using java script ? have u any idea about it ?
StianSandberg 17-Jul-12 4:30am
   
you can't access session-variables directly from javascript. You have to post the form to your server (using a form), then you save the image and store the image path to a session variable just as shown in my example code.
hi hussain,

storing image in session is not a good idea to your application, it degrades the performance of ur application as it consists too large space. instead storing whole image in session u just store that image path in session.
it works fine and will improve ur website performance.

kkakadiya
   
Comments
gmhussain007 17-Jul-12 3:27am
   
how can i upload image & store image path into session using java script ? have u any idea about it ?
gmhussain007 30-Jul-12 5:19am
   
have you any idea about when user login on my website through facebook app that time if user select a image in file upload control that image should be alos upload before/after login through FB emailID

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900