Save programatically in C#

Top  Previous  Next

Save is a bit odd. It will throw an exception if the user chooses not to overwrite an existing file. Here's my solution:


string sFullFileName = CInvSettings.sPlmCacheDir + m_Spec.sBatCode + ".IAM";

if (System.IO.File.Exists (sFullFileName))


   // I need to delete the file if it already exists else AsmDoc.Save will throw an exception

   // if the user says no to ovewrite.

   DialogResult Res = MessageBox.Show(m_Spec.sBatCode + " esiste, sovrascrivere?", "Sovrascrivere?",MessageBoxButtons.YesNo);

   if (Res == DialogResult.Yes)


       // Stop Save() from thowing an exception





       Cursor.Current = Cursors.Default;





AsmDoc.FullFileName = sFullFileName;



Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)