Click here to Skip to main content
16,021,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void DownloadFile(object sender, EventArgs e)
      {
       try
       {
           string filePath = (sender as LinkButton).CommandArgument;
           Response.ContentType = ContentType;
           Response.AppendHeader("Content-Disposition", "attachment;       filename=" + Path.GetFileName(filePath));
           Response.WriteFile(filePath);
           Response.End();
       }
       catch (Exception ex)
       {
           Log(ex.Message, ex.StackTrace);

       }

   }



i am getting this exception


Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at Retail_AddRetailStore.DownloadFile(Object sender, EventArgs e) in c:\Users\nramaraju\Desktop\KJLSOFTWARE\Web\Retail\AddRetailStore.aspx.cs:line 193
Posted
Updated 30-Jan-14 22:40pm
v2

Try like this
C#
protected void lnkDownload_Click(object sender, EventArgs e)
{
LinkButton lnkbtn = sender as LinkButton;
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
string filePath = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
Response.ContentType = "image/jpg";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
Response.TransmitFile(Server.MapPath(filePath));
Response.End();
}


Refer:
Saveupload-files-in-folder-and-download.html[^]
File download from GridView rows in ASP.NET 4.0[^]
This may help.
 
Share this answer
 
v2
Comments
N.RamaRaju 31-Jan-14 5:48am    
no i am not getting this because i kept my link button in inner grid
Gitanjali Singh 31-Jan-14 5:56am    
Ok.Where you are calling the method DownloadFile();?
N.RamaRaju 31-Jan-14 5:59am    
link button in nested grid
Gitanjali Singh 31-Jan-14 6:05am    
For Handling link button in nested gridview
Refer:http://forums.asp.net/t/1918709.aspx
This is normal. You can catch that specific exception and then ignore it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900