Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is XMLDocument.Save an atomic operation?

Is there anyway another process monitoring for files created using XMLDocument.Save() could encounter a partial file? Does it make any difference if Save() is overwriting an existing file?

like image 938
JC. Avatar asked Apr 20 '10 19:04

JC.


1 Answers

If you save like this you shouldn't have any problems.

using (var file = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
{
    xmlDoc.Save(file);
}
like image 197
ChaosPandion Avatar answered Sep 21 '22 10:09

ChaosPandion