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: http://site.com/download.aspx?urlLibrary=http://site.com/magazines/&fileName=1.pdf

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?

  • 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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