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);
}
}
Asked
Active
Viewed 36 times
0

SᴇM
- 7,024
- 3
- 24
- 41

Gurjar_Randeep
- 3
- 4
-
You don't want user to be able to print the pdf files? – Chetan Dec 04 '20 at 05:29
-
i want disble user to save or print pdf file. user can only view the pdf file that's it. thanks – Gurjar_Randeep Dec 04 '20 at 05:32
-
Once the file is opened in user's browser it is almost impossible to control what user can do with it. User can download the file and print it. – Chetan Dec 04 '20 at 05:36
-
Similar question https://stackoverflow.com/q/8870518/8843433 hope this will help – Sujay Dec 04 '20 at 05:37