File is used by another process

ashok.k

Member
Joined
Jun 26, 2009
Messages
13
Programming Experience
Beginner
Hi,

I get the below error while trying to access a file in .NET windows application.

The process cannot access the file 'C:\path\test.XML' because it is being used by another process.

It is a random occurence and I am not sure why this occurs.

I want to check which process is using this file?

Is there a command that i can enter in command prompt to see which process is using this file?

How can i identify which process is using this file?

Thanks
Ashok
 
Post your code. If the only application that should be accessing this file is yours, then the issue lies within your code.


I use the below code to create and save the XML file. When i try to ftp the file from this location to another location it throws the error.

XmlDocument doc = new XmlDocument();
//Call method to create the XML
doc = CreateXML(doc);
string localpath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\" + Properties.Settings.Default.LocalDir;
string filename = "MyOutput.XML";
string writepath = localpath + "\\" + filename;
Encoding enc = new UTF8Encoding(false);
doc.Save(new XmlTextWriter(writepath,enc));

Thanks
Ashok
 
Moderation note to ashok.k: This is a VB.Net forum. Use VB.Net language when you are posting code here.
 
I use the below code to create and save the XML file. When i try to ftp the file from this location to another location it throws the error.

XmlDocument doc = new XmlDocument();
//Call method to create the XML
doc = CreateXML(doc);
string localpath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\" + Properties.Settings.Default.LocalDir;
string filename = "MyOutput.XML";
string writepath = localpath + "\\" + filename;
Encoding enc = new UTF8Encoding(false);
doc.Save(new XmlTextWriter(writepath,enc));

Thanks
Ashok

XmlTextWriter IS the resource that isn't being disposed of, therefore when called, if a previous XmlTextWriter already has a handle on that file in your filesystem, you can't access it with another. You shouldn't be declaring new instances like that anyways. Disposing of them is the best practice.
 
Back
Top