如何从gridview下载文件? [英] How do I download files from a gridview?
本文介绍了如何从gridview下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码。
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
string Filepath = e.CommandArgument.ToString();
string path = MapPath(Filepath);
byte[] bts = System.IO.File.ReadAllBytes(path);
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-type", "application/octect-stream");
Response.AddHeader("Content-Length", bts.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; Filepath=" + Filepath);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();
}
}
但是当我尝试下载时,我收到此错误'是物理路径,但预计会有虚拟路径,任何人都可以帮我这个吗?
But when I try downloading, I get this error "' is a physical path, but a virtual path was expected", can anybody help me with this??
推荐答案
我认为你的错误在于映射路径。你已经做了MapPath(Filepath)
。因此,Filepath
已经是本地路径,但是您将其传递给需要转换虚拟路径的方法。
- Amy
I think your error is in Mapping the path. You didMapPath(Filepath)
already. So,Filepath
is already a local path, but you pass it to a method that expects a virtual path to convert.
--Amy
这篇关于如何从gridview下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文