View Full Version : save image from byte array

01-26-2011, 02:21 PM
Dear All,

I am trying to save a byte array as an image. this byte array may be retrieved from database or it could be retrieved from fileupload control. Then I want to show this image on web page. But this image is not displayed on web page. Here is my code;


byte[] image = new byte[FileUpload1.PostedFile.ContentLength];

HttpPostedFile uploadedImage = FileUpload1.PostedFile;

MemoryStream ms = new MemoryStream(image);

System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);

string path = Path.GetTempPath();

path += "chuss.png";

returnImage.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);

Session["image"] = path;

this.Image1.ImageUrl = path;


Any help will be greatly appreciated.

iSilver Labs
01-26-2011, 06:21 PM

You are using string path = Path.GetTempPath();

In General, you are only able to access files inside root directory where your website files exists.

Try to use a folder inside your root directory to save the files.