Allowing PDF files to open in the browser

By default, most standard file types are allowed to be opened in the browser by SharePoint. However, if you wish to open a PDF, hosted in a document library, you get the dialog if you wish to either save the file or cancel. From a user experience point of view this is bad. Your end-user expects that when he/she clicks a file, he/she can work with it.

This behaviour is configured on the web application level at general settings:

browser file handling

Quoting SharePoint’s description:

Permissive Specifies no headers are added, which provides a more compatible user experience.
Strict Adds headers that force the browser to download certain types of files. The forced download improves security for the server by disallowing the automatic execution of Web content that contributors upload.

So changing the setting to permissive would fix things, right? Considering the fact that you disable all the headers for every file type, this is probably a bad idea.

A more secure approach would be to specifically add the PDF file extension as “allowed”. This can be done by using PowerShell. The following code snippet will allow PDF files to be opened on the web application http://sharepoint:

$webapp = Get-SPWebApplication -Identity http://sharepoint
$webapp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
$webapp.Update()

This method can also be used for other file types.

Advertisements

3 thoughts on “Allowing PDF files to open in the browser

  1. I have faced this issue. Can u please let me know how to handle by using SharePoint object model.

    Thanks for your patients.

    1. First, create an empty SharePoint project. Scope it farm. Next, add a new feature and add a feature receiver so you can write code. Make sure your feature is scoped to WebApplication.

      Uncomment the FeatureActivated method and add the following code:

      SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
      webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf");
      webApp.Update();

      You may also add the following code to the FeatureDeactivating method, so that pdf files are forced to download again once you deactivate the feature.

      SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
      webApp.AllowedInlineDownloadedMimeTypes.Remove("application/pdf");
      webApp.Update();

  2. Pingback: Allowing PDF files to open in the browser « Notes SharePoint Blog

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s