AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Solution: The process cannot access the file because it is being used by another process
Posted by Moderator1 on  6/28/2008 11:02:13 PM 12193 Views
This is an Asp.Net error occurs when you try to access a File object immediately after you use it. This error means the CLR otherwise the .NET Framework doesn’t release the resource yet after it is being used successfully. Or this error can even come when some problem is encountered in between processing that file. The way to handle this is simple.

The ‘using’ statement helps to overcome this problem. File and Font classes are managed objects that can access unmanaged resources such as Images, Fonts, or other files in the server. When we create instances for these classes, it is generally better to instantiate the object in the using statement and limit its scope to the using block. The using statement ensures that Dispose is called even if an exception occurs while you are calling methods on the object and releases the resources used by the objects perfectly.

A general syntax is given below

using (System.Drawing.Image Img = System.Drawing.Image.FromFile(Server.MapPath("Images\\TestImage.jpg")))
{
// Do some operation here
}

Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
The Art & Science of JavaScript - Free 100 Page Preview!
For intermediate JavaScript developers who want to take their JavaScript skills to the next level without sacrificing web accessibility or best practice.
Easing the Migration to Microsoft SQL Server 2005
There are many business and technological reasons for making the move to SQL Server 2005 and SQL Server 2005 Enterprise Edition. In tandem with 64-bit computing platforms, SQL Server 2005 can boost performance by 30% in certain instances, deliver a better database management structure and bolster infrastructure security.
100% Free Subscription until Stock lost.View complete list.
Sponsored by