Reputation: 11
Rather than saving a file silently to a default path, I want to give the user the option to save the excel file. How can I do that?
Upvotes: 0
Views: 4320
Reputation: 34523
I believe it's not really ASP.NET MVC question, but anyway:
Excel.Application excel = new Excel.Application();
Excel.Workbook workbook = excel.Workbooks.Add(Missing.Value) as Excel.Workbook;
...
object filename = excel.GetSaveAsFilename("DefaultName.xls",
"Excel 2000-2003 Workbook (*.xls), *.xls", Missing.Value,
Missing.Value, Missing.Value);
if (!(filename is bool))
{
workbook.SaveAs(filename, Excel.XlFileFormat.xlWorkbookNormal,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
excel.Quit();
}
Upvotes: 2
Reputation: 9513
This question deals with downloading a file in asp.net MVC (by using the FileResultType)...your simply choosing to send an excel file which should still apply.
Upvotes: 0
Reputation: 6077
You need to create a custom ActionResult class which will display the Save As dialog. Phil Haack has an excellent tutorial about that.
Upvotes: 0