[英]download problem asp.net
Hi this is the current version......please help. 嗨,这是当前版本……请帮助。
'> '>
using System; 使用系统; using System.Collections;
使用System.Collections; using System.Configuration;
使用System.Configuration; using System.Data;
使用System.Data; using System.Linq;
使用System.Linq; using System.Web;
使用System.Web; using System.Web.Security;
使用System.Web.Security; using System.Web.UI;
使用System.Web.UI; using System.Web.UI.HtmlControls;
使用System.Web.UI.HtmlControls; using System.Web.UI.WebControls;
使用System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts;
使用System.Web.UI.WebControls.WebParts; using System.Xml.Linq;
使用System.Xml.Linq; using System.IO;
使用System.IO;
public partial class Default2 : System.Web.UI.Page { private void BindGrid() { DirectoryInfo dir = new DirectoryInfo("D:/Pilabs Projects/GlobeDse/globedse website/globedse.com/Uploads"); 公共局部类Default2:System.Web.UI.Page {私有void BindGrid(){DirectoryInfo dir = new DirectoryInfo(“ D:/ Pilabs Projects / GlobeDse / globedse website / globedse.com / Uploads”); FileInfo[] files = dir.GetFiles();
FileInfo [] files = dir.GetFiles(); GridView1.DataSource = files;
GridView1.DataSource =文件; GridView1.DataBind();
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();
}
} }
First, check if your method Downloadfile
is getting hit. 首先,检查您的方法
Downloadfile
是否被命中。 You also did 你也做了
Response.Write(FullPath);
which kinda ruins your output. 这有点破坏您的输出。 I'd rather design it that you redirect to another page which outputs the download.
我宁愿设计它重定向到另一个输出下载的页面。
You're missing a check for postbacks. 您缺少支票回发。 Your Page_Load should look something like this:
您的Page_Load应该看起来像这样:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
When you re-databind the grid, the events are lost. 重新绑定网格时,事件将丢失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.