I'm looking for a solution for Displaying Files on table. Like Windows Desktop Icons. The files' location is stored in the Database. So, I need to Get file locations from database and display that files on table, div or whatever like windows desktop icons. Also it has to available to Download these files. (I think that wont be a problem). Any Solutions? I'm Developing in ASP.NET 4.5
-
Do you want to display the content of the file in table? what are the types of the files?Ray Cheng– Ray Cheng2013-02-27 05:49:01 +00:00Commented Feb 27, 2013 at 5:49
-
what development model are you using MVC/Webforms ....?Devjosh– Devjosh2013-02-27 05:52:47 +00:00Commented Feb 27, 2013 at 5:52
-
I'm using Web Forms. And File types would be .csv files. Very small.Ankhbayar Bayarsaikhan– Ankhbayar Bayarsaikhan2013-02-27 05:58:30 +00:00Commented Feb 27, 2013 at 5:58
Add a comment
|
1 Answer
you can do like this
create template field in GridView and bind values
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" Text = "Download" CommandArgument = '<%# Eval("Value") %>' runat="server" OnClick = "DownloadFile"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
in code behind on download file click
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();
}
Check full code : Download Files from GridView using LinkButton Click Event in ASP.Net using C# and VB.Net
1 Comment
Ankhbayar Bayarsaikhan
Thank you. I've a File Uploader I developed. And this uploader upload files to many directories, folders. So i decided to save file locations to Database. Anyway, thanks a lot. It seems good example.