0

I have a grid view. The data bound to the grid view. I have a column with download link button. When I click on download the file should be downloaded but I got some issue while tying it.

I uploaded files to application folder and the path to database but when I try to download the file it fires an error

    LinkButton lnkbtn = sender as LinkButton;
    GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
    string filePath = gridView1.DataKeys[gvrow.RowIndex].Value.ToString();

    Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
    Response.TransmitFile(Server.MapPath(filePath));
    Response.End();

But my application folder has the uploaded file

enter image description here

2
  • 2
    Use this: Response.TransmitFile(Server.MapPath("/documents/mini/"+filePath)); (instead of your line). Commented Dec 21, 2015 at 23:38
  • Is there any other way rather than this..? Commented Dec 22, 2015 at 0:16

1 Answer 1

2

Your file path is wrong. Server is looking for the file in the site root, here: C:\Users\lagis\Downloads\templgarden\jhvgdfjka.txt. But it seems your desired file is in /documents/mini. So, you need to use the right path(url) for Server.TransmitFile like this:

Response.TransmitFile(Server.MapPath("/documents/mini/" + filePath));
Sign up to request clarification or add additional context in comments.

Comments

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.