Friday, December 23, 2005

Force Download a pdf file

Dim objFile As System.IO.FileInfo

objFile = New System.IO.FileInfo(Server.MapPath("~/file.pdf"))

Response.Clear()

Response.AddHeader("Content-Length", objFile.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment;filename=file.pdf")

Response.AddHeader("Content-Length", objFile.Length.ToString())

Response.ContentType = "application/octet-stream"

Response.WriteFile(objFile.FullName)

Response.Flush()

Response.End()

No comments: