tags:

views:

99

answers:

2

Hi,

I have a code that will loop through each row and each column and export the data to excel. It is all working fine. When the user clicks on "open" file, the system is opening file with different filename. If I give the filename as "test.xls", it is opening the file as "test[1].xls". Is there a way to export with the same filename? Because of this, we are not able to use some excel functionality.

Thanks, sridhar.

A: 

Maybe Windows is adding the [1] when you save it because test.xls already exists or existed previously. Because of that I append the current date to my filenames like so:

Filename = Filename & "_" & String.Format("{0:MM-dd-yyyy}", Now)

You could even add an incrementing number or add the time to the date just to make sure it's unique.

rvarcher
A: 
HttpContext.Current.Response.AddHeader ( "content-disposition",
"attachment;filename=" + pageName + "." + fileExtension );

HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.Cache.SetCacheability ( HttpCacheability.NoCache );
HttpContext.Current.Response.ContentType = "application/vnd." + fileExtension;

System.IO.StringWriter stringWrite = new System.IO.StringWriter ();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter ( stringWrite );
HttpContext.Current.Response.Write ( str.ToString () );
HttpContext.Current.Response.End ();
YordanGeorgiev