在桌上显示文件。 ASP.NET

问题描述:

我正在寻找一个解决方案来显示表上的文件。像Windows桌面图标一样。文件的位置存储在数据库中。所以,我需要从数据库获取文件位置,并将这些文件显示在表格,div或类似windows桌面图标的文件上。它也必须可用于下载这些文件。 (我认为这不会是一个问题)。任何方案?我在开发ASP.NET 4.5在桌上显示文件。 ASP.NET

+0

是否要显示表中的文件?什么是文件的类型? – 2013-02-27 05:49:01

+0

您使用MVC/Webforms ....的开发模式是什么? – Devjosh 2013-02-27 05:52:47

+0

我正在使用Web窗体。和文件类型将是.csv文件。很小。 – 2013-02-27 05:58:30

你可以像这样

GridView创建模板领域和绑定值

<asp:TemplateField> 
      <ItemTemplate> 
       <asp:LinkButton ID="lnkDownload" Text = "Download" CommandArgument = '<%# Eval("Value") %>' runat="server" OnClick = "DownloadFile"></asp:LinkButton> 
      </ItemTemplate> 
     </asp:TemplateField> 

在后面的代码上下载文件点击

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(); 
} 

查看完整密码:Download Files from GridView using LinkButton Click Event in ASP.Net using C# and VB.Net

+0

谢谢。我有一个我开发的文件上传器。这个上传器将文件上传到许多目录,文件夹。所以我决定将文件位置保存到数据库。无论如何,非常感谢。这似乎是一个好例子。 – 2013-02-27 06:00:42