By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

Newly Created Image Not Always Found by Following Code

P: n/a
I am having a problem where the bitmap image that I just created and saved
to disk can not be found but the code in another area of the program. When I
reattempt to access the same image, it always works becuase the image has
been fully saved to that drive by that time. Is there a way to make sure
that a newly created bitmap image is phisically saved to disk before it is

The code that creates that new bitmap image is as follows

Bitmap ImageOut = new Bitmap(NewImageWidth, NewImageHeight);

//other code

ImageOut.Save(NewImagePhisicalPath, FileFormat);

The code that tries to access the new bitmap looks like this

System.Drawing.Image image =
System.Drawing.Image.FromFile(NewImagePhisicalPath );

But this fails some of the time with a file not found execption.

I can add the follow code that should fix this but I am wondering if there
is a better way to flush the file to the disk before accessing it?

while (!(File.Exists(NewImagePhisicalPath)))


//do nothing


string ImageName =
System.Web.HttpContext.Current.Request.MapPath(Pho toImageButton.ImageUrl);
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.