Quantcast
Viewing latest article 2
Browse Latest Browse All 3

Answer by SLaks for File locks when using file.move in c#...how can I stop or fix this

You should close your StreamReader and StreamWriter in using statements, like this:

String tempFile = Path.GetTempFileName(), read = "";using(TextReader pending = new StreamReader("c:\\pending.txt"))using(TextWriter temp = new StreamWriter(tempFile)){    read = pending.ReadLine();    while ((read = pending.ReadLine()) != null)    {        temp.WriteLine(read);    }}File.Delete(@"c:\pending.txt");File.Move(tempFile, @"c:\pending.txt");

Viewing latest article 2
Browse Latest Browse All 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>