SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have document library with name "magazines". containing several pdfs, I'm using caml to view these items on one page pdfs. Added 2 links on this page to the user view pdf online, and to download. Para forçar o download, eu estou redirecionando o usuário para uma nova página:

This page is the following code:

Response.AddHeader("content-disposition", "attachment; filename=" + Request.QueryString["fileName"]);
Response.ContentType = "application/pdf";
Response.WriteFile(Server.MapPath("~/" + Request.QueryString["urlLibrary"] + Request.QueryString["fileName"]));

The download occurs at the user side, so that when you open the pdf of error, and the file has little kybtes over the original pdf. How can I force a download of the document library?

share|improve this question
I don't understand the last sentence... – Steve B Nov 13 '12 at 10:26
The file in the document library has 3 megs, but when I click on my link to download the pdf file comes with 165 kbytes – Tiago Nov 13 '12 at 12:36
Your code can't works, as the files in SharePoint are not store on the file system, but in the content databases. You will have to retrieve the file binary, then serve the binary to the response stream. – Steve B Nov 13 '12 at 13:02

Take a look at this

Different problem but similar solution. It will cause a flash, but you can use the _layouts/download.aspx page from SP to download the file correctly with no errors. I was doing a similar project with infopath and this was the solution I found worked best.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.