Click here to Skip to main content
12,401,995 members (28,647 online)
Rate this:
 
Please Sign up or sign in to vote.
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 1-Mar-10 7:41am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.

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();
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

dialog is showing back to the browser is there solution dialog is showing front to the browser.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 20 Jan 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100