Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" + Request.QueryString["fileName"]);
Response.ContentType = "application/pdf";
Response.WriteFile(Server.MapPath("~/" + Request.QueryString["urlLibrary"] + Request.QueryString["fileName"]));
Response.End();

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.