How to save a XML file that has been generated from XDocument class

Niladri.Biswas
Posted by Niladri.Biswas under C# category on | Points: 40 | Views : 1631
private static void SaveFile(XDocument doc, string fileName, string fileExtension)
{
//show save as dialog
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
{
//Set Save dialog properties
saveFileDialog1.Filter = "Files (*" + fileExtension + ")|*" + fileExtension;
saveFileDialog1.Title = "Save File as";
saveFileDialog1.CheckPathExists = true;
saveFileDialog1.FileName = fileName + fileExtension;

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
doc.Save(saveFileDialog1.FileName);
}
}
}

Comments or Responses

Login to post response