How to give an Excel file a file name when exporting a GridView to Excel 2003 when using ASP.NET 4.0 with C# and VS2010 ?

I'm writing my first ASP.NET 4.0 application using C# with VS2010.

I am trying to export a stored procedure result set to Excel 2003.

When I create the new Excel file, I noticed that it is named DEFAULT.XLS.

DEFAULT is the name of the web page.

Do you know how I can modify my code to assign the newly created Excel file the file name Contacts.XLS rather than Default.XLS?

My code is in the attached file:
Who is Participating?
Chinmay PatelConnect With a Mentor Enterprise ArchitectCommented:

 Response.AddHeader("contenet-disposition", attachment);

Open in new window


 Response.AddHeader("content-disposition", attachment);

Open in new window

Robberbaron (robr)Commented:
1/ you are not writing a file, just output to the webbrowser that you tell it to interpret as an excel file

2/ Excel is smart/dumb enough to accept a textfile as input

3/ Default is the name of any new excel workbook i believe. When you press save.
zimmer9Author Commented:
Excellent catch!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.