I am creating a web app. In my app I have a gridview and a link button inside my gridview. My linkbutton looks like this:
<asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%# Eval("FileData") %>' runat="server" OnClick="lnkDownload_Click"></asp:LinkButton>
In my table there is a link for every file, like(~\userpic\chart.png)
When user clicks on link button the following code should run
protected void lnkDownload_Click(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
if(string.IsNullOrEmpty(filePath))
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "", "alert('No File to download.');", true);
return;
}
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
}
But when I run the code, I am unable to download the file. When I debug this method, debug breakpoint is not being hit. What is wrong with my code?
GridViewcode too.