File System C#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 4
Reputation: sonya_sml is an unknown quantity at this point 
Solved Threads: 0
sonya_sml sonya_sml is offline Offline
Newbie Poster

File System C#

 
0
  #1
May 28th, 2009
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.

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();
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 97
Reputation: VIeditorlover is an unknown quantity at this point 
Solved Threads: 5
VIeditorlover's Avatar
VIeditorlover VIeditorlover is offline Offline
Junior Poster in Training

Re: File System C#

 
0
  #2
May 28th, 2009
visit www.sysinternals.com and find filemon utility - you can monitor any filesystem activity and find what is wrong. You can download handle.exe utility (commandline) to find snapshot of opened files as well.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 71
Reputation: Alxandr is an unknown quantity at this point 
Solved Threads: 9
Alxandr's Avatar
Alxandr Alxandr is offline Offline
Junior Poster in Training

Re: File System C#

 
0
  #3
May 28th, 2009
Most common is a filehandle in your own app that hasn't been closed.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 4
Reputation: sonya_sml is an unknown quantity at this point 
Solved Threads: 0
sonya_sml sonya_sml is offline Offline
Newbie Poster

Re: File System C#

 
0
  #4
May 28th, 2009
Originally Posted by Alxandr View Post
Most common is a filehandle in your own app that hasn't been closed.
Thanks a lot for reply.

Sorry i didn't get what you mean by filehandle not closed?
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 71
Reputation: Alxandr is an unknown quantity at this point 
Solved Threads: 9
Alxandr's Avatar
Alxandr Alxandr is offline Offline
Junior Poster in Training

Re: File System C#

 
0
  #5
May 28th, 2009
  1. StreamWriter tw = new StreamWriter(_documentName);

If I'm not mistaken tw is a filehandle. If you forget to say [icode=c#]tw.Close()[/icode] tw is never closed and you forgot to close a filehandle. This isn't done til you exit your application (though I might be mistaken).
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 4
Reputation: sonya_sml is an unknown quantity at this point 
Solved Threads: 0
sonya_sml sonya_sml is offline Offline
Newbie Poster

Re: File System C#

 
0
  #6
May 28th, 2009
Originally Posted by Alxandr View Post
  1. StreamWriter tw = new StreamWriter(_documentName);

If I'm not mistaken tw is a filehandle. If you forget to say [icode=c#]tw.Close()[/icode] tw is never closed and you forgot to close a filehandle. This isn't done til you exit your application (though I might be mistaken).
well as you see in my example, i have used tw.close(); The second last line.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 71
Reputation: Alxandr is an unknown quantity at this point 
Solved Threads: 9
Alxandr's Avatar
Alxandr Alxandr is offline Offline
Junior Poster in Training

Re: File System C#

 
0
  #7
May 28th, 2009
Yes, but is that your whole program?
If you open that file in another function an not close it, you won't be able to open it again.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC