Free Support Forum - aspose.com

Response object

Hi,

I am creating and saving a excel file in ASP.NET using below code.
Workbook workbook;
workbook.Save(HttpContext.Current.Response, HttpUtility.UrlPathEncode(erg.FileName), ContentDisposition.Attachment, new XlsSaveOptions());

Now I am trying to excess the “Respone” but unable to do so.

Is there any way where I can access the respone.

Thanks

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

You can access Response object by HttpContext.Current.Reponse property. Please see the following code how to write your workbook to response stream.

Please use this code to save your file in XLS or in XLSX format in Response stream.

C#


//Save file and send to client browser using selected format
if (yourFileFormat == “XLS”)
{
workbook.Save(HttpContext.Current.Response, “output.xls”, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));

}
else
{
workbook.Save(HttpContext.Current.Response, “output.xlsx”, ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
}

HttpContext.Current.Response.End();