using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FileDownloadExample
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string filePath = "C:\\Users\\Admi\\Desktop\\abc.txt";
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
// Clear Rsponse reference
Response.Clear();
// Add header by specifying file name
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
// Add header for content length
Response.AddHeader("Content-Length", file.Length.ToString());
// Specify content type
Response.ContentType = "text/plain";
// Clearing flush
Response.Flush();
// Transimiting file
Response.TransmitFile(file.FullName);
Response.End();
}
else Label1.Text = "Requested file is not available to download";
}
}
}
11-16
07-18
1526
06-28
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交