Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StreamReader.Close is leaving the process open

Status
Not open for further replies.

seantuk

Programmer
Mar 22, 2005
62
GB
i am having a problem using files in my c# aspx prog. take a look at the code snippet

Code:
ArrayList fcontents = new ArrayList();
{
  StreamReader sr = new StreamReader(filepath);
  while(sr.Peek() != -1) fcontents.Add(sr.ReadLine());
  sr.DiscardBufferedData();
  sr.Close();
  ((IDisposable)sr).Dispose();
}

filepath is a string containing the filepath. as you can see, i've done everything i can to release the file, but it's still open. i break the program after this by throwing an exception, so i can check the status of any processes on this file on my server, and 90% of the time it's still open.

i need to release this file so i can delete it a little further down my code. how can i do this? alternativly, how can i force a delete?
 
if the file path is a network share then try copying the file locally and see if the same happens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top