Try this if could help..
protected void lnkAttachment_Click(object sender, EventArgs e)
{
LinkButton lnkAttachment = (LinkButton)sender;
GridViewRow row = (GridViewRow)lnkAttachment.NamingContainer;
var fileName = ((LinkButton)row.FindControl("lnkAttachment")).Text;
string sourcePath = Server.MapPath("~/Attachment/Contract/");
string sourceFle = (Server.MapPath("~/Attachment/Contract/" + fileName.ToString()));
string targetPath = this.txtTargetDir.Text;
string targetFle = targetPath + "\\" + fileName;
string result = string.Empty;
this.txtAttachment.Value = string.Empty;
if (!Directory.Exists(targetPath))
{
var ok = System.IO.Directory.CreateDirectory(targetPath);
}
if (!File.Exists(sourceFle ))
{
Tools.MessageBox.Show(this.Page, "Could not foud\\n" + sourceFle);
string uploadedFile = sourceFle;
string resultMes = cCmd.DeleteUploadFileName(uploadedFile);
List<contract_attachmnt> lst = new List<contract_attachmnt>();
lst = cCmd.GetAttachment(this.hfContracNo.Value);
BindAttachment(lst);
return;
}
try
{
Response.ContentType = "application/ms-excel";
var attachmentFle = "attachment; filename=" + fileName;
Response.AppendHeader("Content-Disposition",attachmentFle);
var xx = Path.GetTempPath();
Response.TransmitFile(sourceFle);
Response.End();
}
catch (Exception)
{
result = "Error in downloading file.";
}
Tools.MessageBox.Show(this.Page, result);
}
</contract_attachmnt></contract_attachmnt>
Regards,