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
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 ());
}
}