D
Davidhere40
I'm trying to lock a text file, read its contents, make the text file
empty, then unlock it. I haven't been successful at it yet. The
following code is what I've tried, with no success, because the file
stays locked even after the function finishes.
FileStream fs = new FileStream(fullPath, FileMode.Open,
FileAccess.ReadWrite, FileShare.Delete);
StreamReader streamReader = new StreamReader(fs);
content = streamReader.ReadToEnd();
streamReader.Dispose();
File.Delete(fullPath);
File.Create(fullPath);
fs.Dispose();
The real reason I'm implementing this is below if it matters:
I have to implement a system that allows one computer to tell multiple
other computers connected to a single router, that new files have been
put on their computers. I decided that the best way to do it was to
have a text file that allows me to tell the computer the path of the
new files. I did it this way, because I will have to later port the
program over to java later to save money on not needing to buy
windows, and I'm pretty sure that this method is portable.
Thanks
Dave
empty, then unlock it. I haven't been successful at it yet. The
following code is what I've tried, with no success, because the file
stays locked even after the function finishes.
FileStream fs = new FileStream(fullPath, FileMode.Open,
FileAccess.ReadWrite, FileShare.Delete);
StreamReader streamReader = new StreamReader(fs);
content = streamReader.ReadToEnd();
streamReader.Dispose();
File.Delete(fullPath);
File.Create(fullPath);
fs.Dispose();
The real reason I'm implementing this is below if it matters:
I have to implement a system that allows one computer to tell multiple
other computers connected to a single router, that new files have been
put on their computers. I decided that the best way to do it was to
have a text file that allows me to tell the computer the path of the
new files. I did it this way, because I will have to later port the
program over to java later to save money on not needing to buy
windows, and I'm pretty sure that this method is portable.
Thanks
Dave