all groups > dotnet drawing api > june 2004 >
You're in the

dotnet drawing api

group:

Image.FromFile Not Releasing Files


Image.FromFile Not Releasing Files Ethan Adams
6/29/2004 10:40:50 AM
dotnet drawing api:
I have developed a web application which does something along the following
lines:

string filePath = "C:\somfile.jpg";
using(System.Drawing.Image myImage =
System.Drawing.Image.FromFile(filePath))
{
Response.Clear();
myImage.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
myImage.Dispose();
}

What this code obviously does is take an image in any format and display it
as a JPEG. I also use a modification of it in the application to generate
thumbnails of the images using myImage.GetThumbnailImage(). The problem
with all this is that if someone comes along and wants to delete or save
over somefile.jpg, they get a message that says the file is currently in use
by another person or program and that they should try again later. This
situation persists as long as the web application is running. I don't know
what I can do beyond a using block and calling the Dispose() method to get
this thing to let go of the file. Please help me out with this, and thanks
in advance.

Sincerely,
Ethan Adams

Re: Image.FromFile Not Releasing Files Bob Powell [MVP]
6/29/2004 8:44:17 PM
Open the file with a stream and explicitly close the stream after you do
Image.FromStream.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, snap-to-grid and Layered Windows are
all discussed in May's edition of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml






[quoted text, click to view]

AddThis Social Bookmark Button