I use the File.WriteAllLines()
method in my project. The txt file is to be synced to a remote server (via another application, Autodesk Docs in my case) upon Save action.
I am not sure why, but using WriteAllLines
does not trigger syncing of the file, while opening it and performing a save manually does trigger the sync.
I suspect it's maybe due to WriteAllLines
deleting the existing file and creating a new one instead of overwriting the data inside the file...?
Is there a way to overwrite by deleting the existing the data in the file instead of deleting the existing file and creating a new file?
Am I even right about WriteAllLines
deleting the existing file and recreating it?
FileStream.SetLength
to set the length of the file to zero and then write the data to that stream.Using fs = New FileStream("C:\temp\aab.txt", FileMode.OpenOrCreate)
fs.SetLength(0)
Using sw = New StreamWriter(fs)
'write text...
etc.File.WriteAllLines("temp.txt", Guid.NewGuid().ToString().Select(Function(c) c.ToString()))
repeatedly and see that the creation date will remain the same while the modification date is changed. The file is not deletedUsing sw As New StreamWriter(filename, False)
,Using fs As New FileStream(filename, FileMode.Truncate) Using sw As New StreamWriter(fs)
,Using sw As New StreamWriter(filename, True)
,Using fs As New FileStream(filename, FileMode.Create) Using sw As New StreamWriter(fs)