Vikram
Vikram

Reputation: 1627

XML not getting saved just the time it is saved in .net

I am using XDocument.Save(fileName) method to save the already present xml file at the same location after doing some changes to it and recreating it. Now the scenario is that when user is done with the changes and the file is open in the text editor, sometimes the xml is saved just at the same time and user gets a prompt in the editor that File has been saved. Do you want to reload? but some times it takes to get the prompt in editor which confuses the user if the file has been saved or not. It means it is taking time to save the file. Why is it so.

Upvotes: 0

Views: 72

Answers (1)

Niranjan
Niranjan

Reputation: 76

Try using FileStream object, and then flushing it.

using (FileStream fs = new FileStream(filepath, FileMode.Truncate))
{
    xmlDoc.Save(fs);
    fs.Flush();
}

Upvotes: 1

Related Questions