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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locked Files

Status
Not open for further replies.

yu217171

Programmer
Aug 2, 2002
203
CA
Hi everyone,

I have a routine that reads and parses a bunch of files in a directory. After reading them, I close my StreamReader object but when I try to open the file or delete the file again with Explorer after my routine has ran, I get an Access is Denied error.

Am I missing something in my code? A snippet is provided. Thanks everyone!

Keith

Code:
DirectoryInfo objDI2 = new DirectoryInfo(@"\\servername\folder\");
FileInfo[] fileInfo2 = objDI2.GetFiles("*.txt");

foreach (FileInfo f in fileInfo2)
{				
   StreamReader objSR;				
   try
   {
      string tmpLine;
      objSR = File.OpenText (strPath + f.Name);
    
      while (objSR.Peek() != -1)
      {
         tmpLine = objSR.ReadLine ();
         if ((tmpLine.IndexOf ("search_text") != -1))
         {
            ParseDataLine ("RMD", tmpLine);
         }
      }
      objSR.Close ();
   }

   catch (IOException e)
   {
      Response.Write (e.ToString ());
   }
}
 
Sorry everyone,

I figured things out. It was a permissions issue. I did not have access on the specific folder to delete items.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top