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.Clear(); 
                 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;
                response.TransmitFile(FileName);
                response.Write(FileName);
                 response.Flush();
                 response.End();

Any Profesional can guide me? thanks in advance

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?

have you tried downloading other file extensions like .txt, .doc etc?

Ya. I did try..it just gives me html content..

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)

ok then where are you creating the xls file in your code?

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.