Thursday, May 31, 2012

SharePoint users are being prompted to save a PDF file

If your users are being prompted to save a PDF file as opposed to the document opening directly in the web browser, a solution for this issue is to add that file type (i.e. application/PDF) to the collection of allowed MIME content-types supported by your SharePoint web application.  Here are two different avenues that you can take to solve the problem:

Solution# 1: Use a Feature
Here is some C# code that you can place in a feature (i.e. the SPFeatureReceiver class) that will add the appropriate file type:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
...
// To allow PDF files to be opened in the browser, make certain that the PDF file type is included
// in the list of allowed inline downloaded mime types.  Without this item, the browser will always
// prompt the user to Save the document as opposed to opening the file when the user clicks on the
// PDF document's link.
    if (!web.Site.WebApplication.AllowedInlineDownloadedMimeTypes.Contains(@"application/pdf"))
    {
         web.Site.WebApplication.AllowedInlineDownloadedMimeTypes.Add(@"application/pdf");
         web.Site.WebApplication.Update();
     }
...
}

Solution #2: Use Powershell
Here is a series of Powershell commands that will add the appropriate file type as well:

PS C:\Users\...> $webApp = Get-SPWebApplication http://webapplicationname
PS C:\Users...> $webapp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
PS C:\Users\...> $webapp.Update()

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.