6 Replies - 2743 Views - Last Post: 29 October 2012 - 12:23 AM Rate Topic: -----

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 396
  • Joined: 04-January 11

Client Saving Works in localhost but not when published in server

Posted 01 October 2012 - 03:29 AM

I am trying to export an Excel File with multiple sheets to the client computer. I used the Microsoft.Office.Interop.Excel to create a workbook and save it. Since, the workbook .SaveAs saves to server.

The step-by-step process which I did was:
1. Create workbook with multiple sheets using the Microsoft.Office.Interop.Excel
2. Save the workbook with an appended Guid in the filename for a unique filename
3. Read the workbook in memorystream
4. Store the memory stream in a byte array
5. Use Response.BinaryWrite
6. Delete the file from the server

My codes for saving it in client-side (from step 3 onwards) is

                try
                {
                    using (FileStream fs = File.OpenRead(strFilePath))
                    {
                        MemoryStream ms = new MemoryStream();
                        ms.SetLength(fs.Length);
                        fs.Read(ms.GetBuffer(), 0, (int)fs.Length);

                        byte[] bytStream = ms.ToArray();
                        ms.Flush();
                        ms.Close();

                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + strFilename);
                        HttpContext.Current.Response.AddHeader("Content-Length", bytStream.Length.ToString());
                        HttpContext.Current.Response.ContentType = "application/vnd.xls";
                        HttpContext.Current.Response.BinaryWrite(bytStream);
                        HttpContext.Current.Response.Flush();
                        HttpContext.Current.Response.Close();
                    }
                    File.Delete(strFilePath);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    Response.End();
                }



It is working correctly in localhost so I decided to publish it in server. When I tried to click "Export" it does not show the Dialog with the option for "open" or "Save" neither does it throw an error.

This is my first time working with a memorystream so I am not sure where to look for the error especially, I usually have trouble when it works in localhost but not when published to server.

I hope somebody could help.

Is This A Good Question/Topic? 0
  • +

Replies To: Client Saving Works in localhost but not when published in server

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Client Saving Works in localhost but not when published in server

Posted 01 October 2012 - 04:31 AM

This sounds like an ASP.NET issue, so I'll move it there.
Was This Post Helpful? 0
  • +
  • -

#3 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 396
  • Joined: 04-January 11

Re: Client Saving Works in localhost but not when published in server

Posted 23 October 2012 - 08:43 PM

I just learned what's missing. I was so stupid I did not even remember to ask if there was an excel installed in the server. And the answer is NO. There is none.

Since I use excel workbook with Microsoft.Office.Interop.Excel, I can't make this work in the server. I can't install excel either. So any advice on how can I make it work? Is there a way I can make the Microsoft.Office.Interop.Excel work by adding a dll for example? I am not sure of the approach to use.

Is there a way I can use Microsoft.Office.Interop.Excel in a server without an excel installed?
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,090
  • Joined: 02-July 08

Re: Client Saving Works in localhost but not when published in server

Posted 24 October 2012 - 06:50 PM

Make excel without excel installed.
Was This Post Helpful? 1
  • +
  • -

#5 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 396
  • Joined: 04-January 11

Re: Client Saving Works in localhost but not when published in server

Posted 28 October 2012 - 08:02 PM

View Post_HAWK_, on 24 October 2012 - 06:50 PM, said:



Thanks. I read the article but I do not know how to create multiple sheets using that. Any idea
how to do it?
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,090
  • Joined: 02-July 08

Re: Client Saving Works in localhost but not when published in server

Posted 28 October 2012 - 09:13 PM

I have not used this, just found it in a search. I have done a little with Automation in the past - most of my stuff has been converted to a database. Sorry I could not help further with this.
Was This Post Helpful? 0
  • +
  • -

#7 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 396
  • Joined: 04-January 11

Re: Client Saving Works in localhost but not when published in server

Posted 29 October 2012 - 12:23 AM

View Post_HAWK_, on 28 October 2012 - 09:13 PM, said:

I have not used this, just found it in a search. I have done a little with Automation in the past - most of my stuff has been converted to a database. Sorry I could not help further with this.


Thanks a lot. I appreciate the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1