How To Use Excel.Application.GetSaveAsFilename() Method



TODO:

Have you ever wanted to use the Excel.Application.GetSaveAsFilename method to save your files?


SOLUTION:

Excel.Application excel = new Excel.Application();

FileInfo fileInfo = new FileInfo(txtInputFile.Text.Trim());

//so show the save as, and then filter by current extension only....reason is, that SaveAs() will save in current format, so format changes cannot happen here.
object fileName = excel.GetSaveAsFilename(fileInfo.Name, string.Format("Excel files (*{0}), *{0}", fileInfo.Extension), 1, "Save File Location");

 

NOTES:

This example will display the Save As dialog box.  I limit the box to the current file type, as calling excel.SaveAs(filename) will not change the file type.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading