Monday, December 12, 2005

Open/Save dialog Asp.net

Mostly when we try to export a grid to Excel, the excel file will open in the same window. The following code will open the excel file in new window.

Visual C# .NET Code // Identify the file to download including its path.
string filepath = DownloadFileName;

string filename = System.IO.Path.GetFileName(filepath);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.Flush();
Response.WriteFile(filepath);


No comments: