Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi:
I have developed a SharePoint WebPart using ASP.NET and C# (code behind).
One of the things that needs to be done is to launch the Excel Save As dialog so that the user can save the Excel file.

On the SharePoint Server box, this functionality works correctly. When I click "Export", as expected the Excel "Save As" dialog appears.
However, from a client machine (such as mine), this functionality does not work correctly. When I click "Export", the Excel "Save As" dialog box does NOT appear.

Code snippet where this dialog is being launched…

xlApp.DisplayAlerts = false;
//xlWorkBook.Save();

Microsoft.Office.Interop.Excel.Dialog dialog = xlApp.Dialogs[Microsoft.Office.Interop.Excel.XlBuiltInDialog.xlDialogSaveAs];
dialog.Show(Type.Missing, // document_text
Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, // type_num
Type.Missing, // prot_pwd
Type.Missing, // backup
Type.Missing, // write_res_pwd
Type.Missing, // read_only_rec
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlApp.DisplayAlerts = true;


Do you know what could be causing this difference? Are there some particular things I should investigate?
Thanks for your help,
-Krishna
Posted

The code you wrote is running Excel locally on the server. It is not delivering the file over HTTP. If you want to deliver it over HTTP you would want the browser to display the save as dialog, not Excel.

C#
MemoryStream ms = new MemoryStream();
xlWorkBook.Save(ms,FileFormatType.Default);
ms.Seek(0, SeekOrigin.Begin);   
byte[] buffer = new byte[(int)ms.Length];
buffer = ms.ToArray();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = );
HttpContext.Current.Response.BinaryWrite(fileData);
HttpContext.Current.Response.End();

 
Share this answer
 
Hi T.M:

Thanks for your reply. Sorry for my delay in responding..I was working on a different project, but have now been re-assigned to this..

Have you used aspose to write the code? Because the Save() method on the XlWorkBook object takes no parameters normally. If I try to overload it , I get error messages.

Is there a way to do this without using aspose?

Thanks for your help,
-Krishna
 
Share this answer
 
dialog is showing back to the browser is there solution dialog is showing front to the browser.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900