Click here to Skip to main content
15,945,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

I have created one blank excel file with "Sample1" sheet name and placed in one folder. My requirement is, I have one button and when button is clicked, I need to write some data in excel file and then excel file will be downloaded, this all concept is written in [WebMethod] which is called by jquery ajax method.

When [WebMethod] is called then I copy blank excel file in specific folder and write content into it and then download that excel file, My problem is, I want to download excel file with specific sheet name. Suppose, sample blank excel file sheet name is "Sample1" then downloaded file sheet name should be "Sample1" but when I open downloaded file then sheet name is changed with the file name.

        context.Response.ContentType = GetMimeTypeByFileName(System.IO.Path.GetExtension(fileExtension);
        context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

virusstorm 8-Aug-13 11:42am    
When you copy the Excel file and write the data, are you writing it to the "Sample1" sheet?
Imran Khan Pathan 16-Aug-13 5:49am    
yes, actually my file name is "SampleExcelSheet" with sheet name is "Sample1" and when I copy, My file name will be "Sample1" with sheet "Sample1", but suppose, when you download first time, it will be "sample1" but second time, it will be "Sample1_1" something like that, no matter what will be file name during download, but sheet name should maintain its name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900