Aspose.Cells.GridWeb Save Command

I want the save button on the GridWeb control to download the Excel file to user’s browser. Here is a code example from the Grid.Web demo solution:

protected void GridWeb1_SaveCommand(object sender, EventArgs e)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

{

// Generates a temporary file name.

string filename = System.IO.Path.GetTempPath() + Session.SessionID + ".xls";

// Saves to the file.

this.GridWeb1.WebWorksheets.SaveToExcelFile(filename);

// Sents the file to browser.

Response.ContentType = "application/vnd.ms-excel";

//Adds header.

Response.AddHeader("content-disposition", "attachment; filename=book1.xls");

// Writes file content to the response stream.

Response.WriteFile(filename);

// OK.

Response.End();

}

However, I do not want to physically write the temporary file to the web farm. I am looking for a function similar to the Aspose.Cells.Workbook.Save() that supports a SaveType of OpenInBrowser.

Hi,

Could you change a line of your code for your requirement:

// Generates a temporary file name.<o:p></o:p>

string filename = System.IO.Path.GetTempPath() + Session.SessionID + ".xls";

// Saves to the file.

this.GridWeb1.WebWorksheets.SaveToExcelFile(filename);

// Sents the file to browser.

Response.ContentType = "application/vnd.ms-excel";

//Adds header.

Response.AddHeader("content-disposition", "inline; filename=book1.xls");

// Writes file content to the response stream.

Response.WriteFile(filename);

// OK.

Response.End();



Thank you.

Doesn’t the function SaveToExcelFile physically writes to the file system? I will not be able to physically write to the file system. I need a stream type object.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

// Saves to the file.

this.GridWeb1.WebWorksheets.SaveToExcelFile(filename);

Hi,

Well, you may save the file to streams, see the following sample code:

// Generates a memory stream.
System.IO.MemoryStream ms = new System.IO.MemoryStream();

// Saves to the stream.
this.GridWeb1.WebWorksheets.SaveToExcelFile(ms);

// Sents the file to browser.
Response.ContentType = “application/vnd.ms-excel”;

//Adds header.
Response.AddHeader(“content-disposition”, “attachment; filename=book1.xls”);

// Writes file content to the response stream.
Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length);

// OK.
Response.End();


Thank you.