如何从gridview下载所选文件。我需要使用session在另一个页面中下载所选文件 [英] How to download a selected file from gridview. I need to download the selected file in another page using session

查看:80
本文介绍了如何从gridview下载所选文件。我需要使用session在另一个页面中下载所选文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,我创建了一个网站,用户登录并搜索文件并尝试下载。但是用户只有在提供密钥后才能下载它。我的问题是如何在验证后从gridview下载所选文件?

解决方案



检查这些:

http:// www .aspsnippets.com / Articles / download-multiple-files-as-Zip-Archive-File-using-GridView-in-ASPNet.aspx [ ^ ]

http://www.bipinjoshi.net/articles/2cd48325-5523-4442- 98a8-63f12dba567b.aspx [ ^ ]


您好,您可以通过不同的方式实现这一目标。如果您的网格包含要下载的文件的uri,则只需通过将下载文件路径作为参数调用以下函数。

  public   void  DownloadFile( string  filePath)
{
Response.ClearContent();
Response.Clear();
Response.ContentType = APPLICATION / OCTET-STREAM;
字符串标题= 附件;文件名= \ + FileName.pdf + \;
Response.AppendHeader( Content-Disposition,Header);
System.IO.FileInfo Dfile = new System.IO.FileInfo(filePath);
Response.WriteFile(Dfile.FullName);
// 不要忘记添加以下行
Response.End ();
}



我希望这会对你有所帮助。 :)


I am new to this, I have created a website in which user logs in and searches a file and tries to download it. But user can download it only after giving a secret key. My question is how to download the selected file from gridview after the validation?

解决方案

Hi,
Check these :
http://www.aspsnippets.com/Articles/Download-multiple-files-as-Zip-Archive-File-using-GridView-in-ASPNet.aspx[^]
http://www.bipinjoshi.net/articles/2cd48325-5523-4442-98a8-63f12dba567b.aspx[^]


Hi, You can achieve this using different ways. If your grid contains uri of the file you want to download then just call below function by passing download file path as a parameter.

public void DownloadFile(string filePath)
{
  Response.ClearContent();
  Response.Clear();
  Response.ContentType = "APPLICATION/OCTET-STREAM";
  String Header = "Attachment; Filename=\"" +   "FileName.pdf" + "\"";
  Response.AppendHeader("Content-Disposition", Header);
  System.IO.FileInfo Dfile = new System.IO.FileInfo(filePath);
  Response.WriteFile(Dfile.FullName);
  //Don't forget to add the following line
  Response.End();
}


I hope this will help you. :)


这篇关于如何从gridview下载所选文件。我需要使用session在另一个页面中下载所选文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆