[英]download problem asp.net
嗨,這是當前版本……請幫助。
'>
使用系統; 使用System.Collections; 使用System.Configuration; 使用System.Data; 使用System.Linq; 使用System.Web; 使用System.Web.Security; 使用System.Web.UI; 使用System.Web.UI.HtmlControls; 使用System.Web.UI.WebControls; 使用System.Web.UI.WebControls.WebParts; 使用System.Xml.Linq; 使用System.IO;
公共局部類Default2:System.Web.UI.Page {私有void BindGrid(){DirectoryInfo dir = new DirectoryInfo(“ D:/ Pilabs Projects / GlobeDse / globedse website / globedse.com / Uploads”); FileInfo [] files = dir.GetFiles(); GridView1.DataSource =文件; GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
private void Downloadfile(String fileName, String FullFilePath)
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.TransmitFile(FullFilePath);
Response.End();
}
protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
String[] fileInfo = e.CommandArgument.ToString().Split(';');
String FileName = fileInfo[1].ToString();
String FullPath = fileInfo[0].ToString();
Downloadfile(FileName, FullPath);
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.PageIndex = e.NewPageIndex
BindGrid();
}
}
首先,檢查您的方法Downloadfile
是否被命中。 你也做了
Response.Write(FullPath);
這有點破壞您的輸出。 我寧願設計它重定向到另一個輸出下載的頁面。
您缺少支票回發。 您的Page_Load應該看起來像這樣:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
重新綁定網格時,事件將丟失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.