Hi, I'm using VS 2005 and C# to make a website.
I got a page that exports my report to an xls file (first reading a template, then poulating all the fields, then saving it to another file and finally sending it through a "Response.Write File").
What I'm trying to do is save the whole xls file to the response.writef ile and avoid disk usage.
here's the working code I got (the relevant part):
and what I want to do would be something like:
Obviously that doesn't work, but I cant find any examples explaining what I want to do.
I got a page that exports my report to an xls file (first reading a template, then poulating all the fields, then saving it to another file and finally sending it through a "Response.Write File").
What I'm trying to do is save the whole xls file to the response.writef ile and avoid disk usage.
here's the working code I got (the relevant part):
Code:
objBook.SaveAs(fPath + "\\" + fName, Excel.XlFileFormat.xlWorkbookNormal,
null, null, false, false, Excel.XlSaveAsAccessMode.xlShared,
false, false, null, null, null);
objBook.Close(Excel.XlSaveAction.xlDoNotSaveChanges, null, null);
objApp.Workbooks.Close();
objApp.Quit();
objBook =null;
objSheet =null;
objApp =null;
range =null;
GC.Collect();
Response.AppendHeader("content-disposition",
"attachment; filename=" + fName);
Response.ContentType = "application/x-msdownload";
Response.WriteFile(fPath + "\\" + fName);
Code:
FileStream fsXLS = new FileStream();
objBook.SaveAs(fsXLS, Excel.XlFileFormat.xlWorkbookNormal,
null, null, false, false, Excel.XlSaveAsAccessMode.xlShared,
false, false, null, null, null);
objBook.Close(Excel.XlSaveAction.xlDoNotSaveChanges, null, null);
objApp.Workbooks.Close();
objApp.Quit();
objBook =null;
objSheet =null;
objApp =null;
range =null;
GC.Collect();
Response.AppendHeader("content-disposition",
"attachment; filename=" + fName);
Response.ContentType = "application/x-msdownload";
Response.WriteFile(fsXLS);
Comment