24 July 2007

PDF's in .NET

This may be simple for most, but this is my final word on how to display a PDF in a browser window. You have to pass in the server path string serverpath = Server.MapPath(path);


public
static
void DisplayPDF(string pdfPath, HttpResponse Response)

{


FileInfo fileInfo = new
FileInfo(pdfPath);


if (fileInfo.Exists)

{

Response.ClearHeaders();

Response.ClearContent();

Response.Clear();

Response.BufferOutput = true;

Response.ContentType = "application/pdf";

Response.AddHeader("content-length", fileInfo.Length.ToString());


Response.AddHeader("content-disposition", "inline;filename=\"filename.pdf\"");

Response.Flush();


Response.TransmitFile(pdfPath);


}


}


0 Comments:

Post a Comment

Links to this post:

<< Home