Pages

2009-04-27

觸發檔案下載視窗

ASP.NET網頁中,要觸發一個file下載,通常用下面語法即可。 
string filePath = "c:\download\test.doc";
Response.Clear();

// Specify the Type of the downloadable file.
Response.ContentType = "application/octet-stream";

// Set the Default file name in the FileDownload dialog box.
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

Response.Flush();

// Download the file.
Response.WriteFile(filepath);

No comments: