【问题标题】:Download image via gridview hyperlink giving error c#通过gridview超链接下载图像给出错误c#
【发布时间】:2016-08-01 14:52:54
【问题描述】:

请注意,图像是从解决方案本身的文件夹中绑定的。

我知道问题是我不应该使用 Server.Mappath,但任何人都可以提出解决方法 因为使用 Directory.GetFiles 和 Response.TransmitFile 也不起作用.. 我应该怎么做才能让它工作。

【问题讨论】:

标签: c# asp.net gridview


【解决方案1】:

C#代码

protected void DownloadFile(object sender, EventArgs e)
  {
    string filePath = (sender as LinkButton).CommandArgument;
    Response.ContentType = ContentType;
    Response.AppendHeader("Content-Disposition", "attachment; filename=" +        Path.GetFileName(filePath));
    Response.WriteFile(filePath);
    Response.End();
  }

【讨论】:

  • response.TransmitFile(FilePath);或者 Response.WriteFile(filePath);
猜你喜欢
  • 1970-01-01
  • 2019-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-02
  • 1970-01-01
相关资源
最近更新 更多