Link to home
Start Free TrialLog in
Avatar of Karl66
Karl66

asked on

C# deleting an open file - closing all files first?

C# VS2008 Windows app

I check a bunch of text files by checking if they exist and searching for and displaying some data. Later I offer the user a chance to delete all the text files but VS studio has an exception that the file is in use? I didn't know I was leaving the files open - can I issue something to close all files at one?

Karl66
Avatar of Karl66
Karl66

ASKER

Here is an example -

                  StreamReader sr = File.OpenText(path + @"\tmp\file.txt");
                    while ((input = sr.ReadLine()) != null)
                    {
                          <... bunch of searches ...>
                     }
                     if (Directory.Exists(path + @"\tmp"))
                        System.IO.Directory.Delete(path + @"\tmp", true); <- says cannot delete \tmp in use
ASKER CERTIFIED SOLUTION
Avatar of JimBrandley
JimBrandley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial