开发者

Cannot Delete File using C# Windows Forms Application

I am opening a file from a location (say, X) in a PictureBox.

After that, if the user clicks on a button say "btn1" then I copy the file 开发者_如何学编程from Location X to Location Y using File.Copy().

After that I set the Picturebox1.Image=null; ...and use File.Delete(X);

At this point Visual studio shows me the exception that The file cannot be deleted as it is being used by another process.

Any ideas as to why would that be?


Call Picturebox1.Image.Dispose().


You can use File.Move() as workaround http://msdn.microsoft.com/en-us/library/system.io.file.move.aspx


Make sure you are disposing the original Image.

Otherwise, another program has a handle on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜