Click here to Skip to main content
11,417,972 members (49,027 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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:

 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 2-Apr-13 0:34am
Edited 2-Apr-13 0:36am
v2

1 solution

Rate this: bad
good
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.
  Permalink  
v3
Comments
V G S Naidu A at 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ő at 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 at 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ő at 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
0 Sascha Lefévre 350
1 Abhinav S 339
2 OriginalGriff 315
3 Sergey Alexandrovich Kryukov 245
4 deepankarbhatnagar 121
0 Sergey Alexandrovich Kryukov 9,405
1 OriginalGriff 7,802
2 Maciej Los 3,758
3 Abhinav S 3,637
4 Sascha Lefévre 3,218


Advertise | Privacy | Mobile
Web04 | 2.8.150427.4 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
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