protected void grdauditDocumentDetail_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
pclsAuditDocumentsqlDL obj = new pclsAuditDocumentsqlDL();
clsAuditDocumnetSqlBL objAuditDoc = new clsAuditDocumnetSqlBL();
int Docid = Convert.ToInt32(e.CommandArgument);
// Convert.ToInt32((row.FindControl("lblDocid") as Label).Text);
objAuditDoc.DeleteAuditDocbyAuditDocid(Docid);
fillgrdAuditDetail();
lblMsg.Text ="Record Deleted Successfully!";
}
if (e.CommandName == "Download")
{
Downolad(e.CommandArgument.ToString(), System.IO.Path.GetExtension(e.CommandArgument.ToString()));
}
}
private void Downolad(string filename, string ext)
{
string type = "";
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;
case ".txt":
type = "text/plain";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
case ".jpg":
case ".jpeg":
type = "Application/jpg";
break;
case ".xls":
type = "Application/xls";
break;
case ".pdf":
type = "Application/pdf";
break;
}
long FileSize;
string path = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + ConfigurationManager.AppSettings["AuditDocumentspath"] + "/" + filename;
if (File.Exists(path))
{
System.IO.FileStream MyFileStream = new System.IO.FileStream(path, System.IO.FileMode.Open);
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize + 1];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
MyFileStream.Close();
Response.ContentType = "application/" + type;
Response.AddHeader("content-disposition", "attachment; filename=" + filename + ";");
Response.BinaryWrite(Buffer);
Response.End();
}
else
{
MessageBox.Show(this, "File Does not exist in Directory!");
}
}
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment