I use a savefiledialog in the application to save the file. If the same filename already exists I get a popup asking if i want to replace or not. If i give no I get unexpected system exception. Below is part of code
string fname1 = "";
saveFileDialog.Title = "Save the Proofer Report";
saveFileDialog.Filter = "Excel Files (*.xls)|*.xls";
saveFileDialog.FilterIndex = 0;
saveFileDialog.InitialDirectory = "MyDocuments";
saveFileDialog.FileName = "Proofer Report";
aveFileDialog.AddExtension = true;
saveFileDialog.ShowHelp = true;
// saveFileDialog.ShowDialog();
Invoke((Action)(() => { saveFileDialog.ShowDialog(); }));
fname1 = saveFileDialog.FileName;
xlWorkBook.SaveAs(fname1, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
//system exception during save as
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
stack trace
at Microsoft.Office.Interop.Excel._Workbook.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local) at ProoferXML.MainForm.ProcessDocument(BackgroundWorker worker, DoWorkEventArgs e) in D:\ProoferXML\WindowsFormsApplication1\WindowsFormsApplication1\MainForm.cs:line 665 at ProoferXML.MainForm.prooferWorker_DoWork(Object sender, DoWorkEventArgs e) in D:\ProoferXML\WindowsFormsApplication1\WindowsFormsApplication1\MainForm.cs:line 1457
While Saving the excel using workbook.saveAs getting the Exception from HRESULT: