Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am taking the content of Image in byteArray format from database and displaying the Content image tag in Asp.net. Here the problem is when i save the image file in Specific location in my working folder and displaying the image working fine.

But if i trying to save the image in temporary folder and giving the temporary folder url to image tag it doesn't displaying the image. The code is:

C#
 Bitmap bi = new Bitmap(byteArrayToImage(FileUpload1.FileBytes));

 //This code working fine

 string path = Server.MapPath("Images/") + FileUpload1.PostedFile.FileName;
         bi.Save(path , ImageFormat.Jpeg);
        Image1.ImageUrl = "Images/" + FileUpload1.PostedFile.FileName;



//This code didn't displaying the image.

         bi.Save(Path.GetTempPath() + FileUpload1.PostedFile.FileName, ImageFormat.Jpeg);
        Image1.ImageUrl = Path.GetTempPath() + FileUpload1.PostedFile.FileName;

what is the problem with the tempFolder here.I am using the Windows7 operating system. Here i am using the temparory folder for automatically deleting the created images in folder.
Please give to useful technique here.

Thank you
Posted
Updated 1-Apr-13 23:36pm
v2

1 solution

Bad design.
Think of your application as running on a web server (actually the development server is a simple web server). Will the web server serve from it's OS temporary folder? Never.
You can only use image sources that are in the served scope of your web server. And be aware, that the browses needs logical served paths, not physical ones - since it can not access server physical file system.
 
Share this answer
 
v3
Comments
V G S Naidu A 3-Apr-13 0:30am    
can u suggest me a good solution to what to do. i am new to Asp.net
Zoltán Zörgő 3-Apr-13 2:28am    
In your original post you have presented the good solution too (the first, working alternative), what is wrong with that one?
V G S Naidu A 4-Apr-13 0:35am    
If i use the first code it creates the images in Image folder of the source code, i need to delete the all the images because we could not provide the space to all the images in the database. so i choosed to create the image in tempPath of the local system so those files will be destroyed by Operating system only. Am i right. But it doesn't taking the absolute path of the temporary folder instead it taking virutal folder (like - http://localhost:1808//Project folder//C://Users/AppData/temp/images/image1.jpg) which is not right.
Zoltán Zörgő 4-Apr-13 1:59am    
Your approach is not good. And quite confusing too. It you have storage problems, extend storage or rethink disk/database usage. Putting something in the temp folder and not in an other folder won't spare you space. And you have no control over it when the operating system will delete it. And by the way the url you put here as example will never work.
Just a note: if the problem is that you want to store files in the database, but you have Express with database size limitation, you might consider using FILESTREAM feature, which is just for that. You can manipulate them with t-sql, but the binary data is stored on the file system and you those files does not count into Express database limits.
So first clarify what are your needs, not how did you tried to solve them in the wrong manner...

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