底下說明如何提供檔案給使用者下載(不必提供URL給使用者點選)
程式碼如下:
protected void Button1_Click(object sender, EventArgs e)
{
string fileName = @"c:\FAXTEST.doc";
Response.Clear();
//指定下載的檔名
Response.AddHeader("content-disposition", "attachment;filename=test.doc");
Response.ContentType = @"application/octet-stream";
System.IO.FileStream downloadFile =
new System.IO.FileStream(fileName, System.IO.FileMode.Open);
downloadFile.Close();
Response.WriteFile(fileName);
Response.Flush();
Response.End();
}
沒有留言:
張貼留言