Click here to Skip to main content
13,003,589 members (61,276 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am taking the content of Image in byteArray format from database and displaying the Content image tag in 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:

 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 1-Apr-13 23:34pm
Updated 1-Apr-13 23:36pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100