We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Why does this download pdf file code from a non-direct link damage the file?

Medium Priority
Last Modified: 2012-08-14
The code allows download.
But when the file is opened.
The file is damaged.
<%Option Explicit%>
	Dim adoStream, stream, fileName, mimeType
	Set adoStream = Server.CreateObject("ADODB.Stream")
	fileName = Request.QueryString("file")
	mimeType = Request.QueryString("mime")
	adoStream.Type = adTypeBinary
	'adoStream.LoadFromFile Server.MapPath(fileName)
	adoStream.LoadFromFile Server.MapPath("/s1QZAkAeAKT1chsRu/" & fileName)
	If adoStream.Type = adTypeBinary Then
	stream = adoStream.Read()
	stream = adoStream.ReadText()
	End If
	Set adoStream = Nothing
	Response.Buffer = True
	Response.AddHeader "content-disposition", "attachment; filename=" & fileName
	Response.AddHeader "content-length", Len(stream)
	Response.ContentType = mimeType
	Response.BinaryWrite stream

Open in new window

Watch Question

Don't ask why, but try adding the below to the very top of your page and see what happens?   If it works you will need to redo your code as this is a special call for PDFs files and will most likely break all other file types - the whole thing gets a bit technical and I can't remember where I read the article that suggested this.
<!--METADATA TYPE="TypeLib" UUID="{414FEE4B-2879-4090-957E-423567FFCFC6}"-->

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.