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

BUG: System.Drawing.Image.FromFile locks file

P: n/a

When I use the method "System.Drawing.Image.FromFile(pictureFile)" where
pictureFile is the path to a valid image file, the file is locked even
minutes after the statement executes. This code is in a web service hosted
in IIS on Windows XP. Typically, I have to run IISRESET from the Command
Line to be able to rename the file.

My work around is to use a different method:

Dim fs As FileStream = New FileStream(pictureFile, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)
dim pic As Image = System.Drawing.Image.FromStream(fs)
fs = Nothing

With this method, I open the file for Read Shared, use the FromStream
method, and close the file stream immediately.

The VS.NET team here may want to verify this.

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.