Skip to content

File System C#

sonya

Asked May 28, 2009, 9:03 AM EDT2 answers
Share
LinkedInX

Hi,
Can someone please help me.
I am getting error: The process cannot access the file 'c:\reports\PaymentDetailReport.xml' because it is being used by another process. in following function.

This method is suppose to be called couple of times. but at second time, it throws the error. I have even closed tw.

TypeScript
private void saveReport(string reportName, string data)
{
  if (reportName == "PaymentReport")
   {
    StreamWriter tw = new StreamWriter(_documentName);
    tw.WriteLine(data, true);
   StreamWriter masterPSDR = File.AppendText("C:\\reports\\masterPSDR.xml");
   masterPSDR.WriteLine(data, true);
    tw.Close();
    masterPSDR.Close();
}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0

    you may have a threading issue.  if the file is accessed before it is closed, it will throw the error you are getting.  Make sure you lock the area of the thread  lock(this) {}

    0
  • 0
    Thanks mike for the reply.
    I am not using any threading.
    0