0

My intranet site needs to allow users to view PDF documents without prompting them to download/save the document to their computer.

Currently, this works when users try to view official documents:

  • User clicks URL for the file they want to view
  • PDF file is loaded in their browser
  • User is not prompted to download

When anyone tries to click a URL with a direct link to a working copy instead, it always prompts the user to save the download to their computer.

I've been looking for hours trying to figure out why this could be happening. Here is what I know so far:

  • Documents in the official and working copy sections are named differently, but have the same number of characters in their name
  • The link which lets a user view the official document in the view is:

<li class="Item"><a class="tile" href="@d.URL">@d.Description<br />@d.FileDate</a>

  • The link for the working copy document is:

<li class="Item"><a class="tile" href="@d.URL">@d.Description<br />@d.FileDate</a>

(In both links, @d represents an individual document the user can click; the viewmodel has two individual types of documents - which are both select lists - which are loaded on the page: official documents, and working copies, or working documents.)

  • Both of these links are in the same view. The "using" statement at the beginning of the view is:

@using (Html.BeginForm("Case", "Portal", FormMethod.Post, new { enctype = "multipart/form-data" }))

(The enctype is set to multipart/form-data because users upload files in this view.)

I already tried taking one of the official documents (which always opens without download prompts) and adding it to the working documents section, just to see if there is a change. When I do this (to view the PDF file in its new location), I am immediately given a download prompt.

I am sincerely confused. If my intranet site was having system-wide trouble viewing PDF files in-browser, no one would be able to view files in their browser, and always be asked to download them.

I've tried viewing other stackoverflow questions (such as this one) to see how appending "content-type" or similar descriptors to the response can help resolve the problem, but I'm unsure how to do this and whether it will help me. (Again, I'm baffled why one hyperlink allows me to view in-browser, and the other does not.)

One final consideration: I'm unable to review the properties for both locations where the files are actually placed, and I'm wondering if these "folders" need to have their settings checked. These documents are stored on a SharePoint 2010 site, and the user can upload several working documents to add to the list. (Users can only upload to the working documents section, not the official section.)

Community
  • 1
  • 1

1 Answers1

2

Whether or not the user is prompted to download depends on two factors: 1) What Content-Disposition header is sent and 2) the capabilities of the client.

The second is easy to rule out. If the browser has a PDF reader plugin installed or comes with one by default (Chrome), then it will be able to view the PDF within the browser. If it does not, it will be forced to download, regardless. If you can view any PDFs at all in the browser, this shouldn't be a concern.

The first is the more likely cause. The Content-Disposition header can be set to either attachment (download) or inline (view in client), along with an optional filename. If the the filename is set, but not attachment or inline, the default is attachment.

You haven't specified how the links to these PDFs function. If they're directly to static files actually present on the filesystem, then the disposition is decided by the web server, and really, you'd be seeing either all of them download or all of them viewed in the browser.

If rather, you have an action that is returning file content, then you control the disposition and you should check the actions that return these files to ensure that it's being set to what you think it should be.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • Chris, thank you for your reply. Clients using the site will browse on IE on Surface 3 Pro tablets. They will have PDF reader software installed (at minimum). The links go to static PDF files which exist in SharePoint directories. I'm wondering if any setup differences between directories would influence how the files are accessed. I'm assuming that if I forced `Content-Disposition` to be set to `inline`, users would still be able to right-click and save the document if they chose; regardless, can I return updated disposition headers in the view, or do I need to specify in a controller action? – InspectorGadget Feb 06 '15 at 14:50