Newly Created Image Not Always Found by Following Code

E

Earl Teigrob

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
accessed?

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(PhotoImageButton.ImageUrl);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top