Hi guys, I have a problem which make me headache.
Suppose I wish to download excel file from what I have browse and some logic processing.

But it returns me aspx.page content, in short a html page.

String FileName = excelApp.ActiveWorkbook+".xls";
                 String FilePath = input.PostedFile.FileName;
                 System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                 response.ContentType = "application/vnd.ms-excel";
                 response.AddHeader("content-disposition",  "excelApp.ActiveWorkbook;Filename="+FileName);
                 response.AddHeader("content-length", FileName.Length.ToString());
                 response.Charset = "";
                 this.EnableViewState = false;

Any Profesional can guide me? thanks in advance

Edited 5 Years Ago by Stefan_Lam88: n/a

Hi I did google search alot until I come here. even though I didnt put content type..it got nothing effect on my download content.Any opinions?

My project is browse a csv file from localhost machine and download it in xlsx file but the link u give me seems like upload to a website..

the code contained in that is for uploading as well as downloading file.... so you want to say that you have csv file and you want to download the contents in xls file?

In short, first I have to browse a .csv file and then process some logics and finally I have to convert to .xls or .xlsx(if possible). Thus, I should say I download it in excel format(xls, xlsx)

Thanks abelLazm for replying. I m able to solve now.
it's all due to I didnt save the xls (completed) in server and process to the client side.

And some response object I didnt use..

excelApp.ActiveWorkbook.SaveAs(System.Web.HttpContext.Current.Server.MapPath("xxx.xls"), Excel.XlFileFormat.xlOpenXMLWorkbook,
                           Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                           Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

For sharing knowledge purpose..

This question has already been answered. Start a new discussion instead.