Saurav Gurjar

Saurav Gurjar

  • 1.3k
  • 385
  • 11.4k

how to hide print button when pdf is opened in browser using asp.net

Dec 3 2020 11:35 PM
protected void lnkView_Click(object sender, EventArgs e)
{
LinkButton lbkFile = (LinkButton)sender;
string FilePath = Server.MapPath("~/Uploads/Improvementdata/" + lbkFile.CommandArgument);
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if (FileBuffer != null)
{
string extn = Path.GetExtension(lbkFile.CommandArgument);
if (extn == ".jpg" || extn == ".png" || extn == ".JPG" || extn == ".jpg")
{
Response.ContentType = "image/jpeg";
Response.AddHeader("content-length", FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
else
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
}
}

Answers (1)