hellow every one i have this following code this function save a list object into xml file it opens every time savefiledialoge i just want to add some code that if a file is already saved it will not open savefiledialge but over write it just like save function in ms word or some other editors. this function behaves like save as function i want both save and save as functionality if file not saved dialogue will open and if it is already saved it just over write.
string file = "";
try
{
if (_AllTests.Count > 0)
{
LogMessage(String.Empty);
saveFileDialog1.Filter = "XML files (*.xml)|*.xml";
saveFileDialog1.InitialDirectory = Application.StartupPath + "\\ SavedTest\\";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
file = saveFileDialog1.FileName;
foreach (Test t in _AllTests)
{
if (t._testName == tabControl2.SelectedTab.Text)
{
LogMessage("Saving " + file + "...");
TestToXML(t, file);
LogMessage("Saved Successfully.");
}
}
}
}
else
{
StatusMessage("No Test Found in Test Explorer!");
}
}
catch(System.Exception ex)
{
LogMessage("Error Occured While Saving Test in XML File!");
DebugMessage(ex.ToString());
}