2

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

3
  • Do you want to display the content of the file in table? what are the types of the files? Commented Feb 27, 2013 at 5:49
  • what development model are you using MVC/Webforms ....? Commented Feb 27, 2013 at 5:52
  • I'm using Web Forms. And File types would be .csv files. Very small. Commented Feb 27, 2013 at 5:58

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.