Wednesday, April 11, 2012

Open PDF files in browser


In SharePoint when you try to open a PDF you are forced to download the file. Downloading can be avoided. To fix this we need to do some config changes in Central Admin. There are two options to achieve the same
First option –
  • Go to Central Administration > Application Management > Manage web application under web application
  • Select the web application then click on general settings from Ribbon > then Change “Browser File Handling” to Permissive.
  • Click Ok.
  • Do an IISRESET
Note - From a security point of view I don't think it is a good idea to change the 'Browser File Handling' to 'Permissive'.

Here is another option to allow PDF to be opened in browser from Sharepoint.

  1. Open the "SharePoint 2010 Management Shell", running as Farm Administrator;
  2. Execute the following commands – (Replace < YourSiteURL> with your web application url)  

$webApp = Get-SPWebApplication http://YourSiteURL
$webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
$webApp.Update()

           Or you can save as PowerShell script and execute that
            Here is script  

           $webApp = Get-SPWebApplication http://YourSiteURL
           If ($webApp.AllowedInlineDownloadedMimeTypes -notcontains "application/pdf")
           {
               Write-Host -ForegroundColor White "Adding Pdf MIME Type..."
               $webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
               $webApp.Update()
               Write-Host -ForegroundColor White " Pdf MIME Type added and saved."
            } 
            Else {
                  Write-Host -ForegroundColor White "Pdf MIME type is already added."
            }

      3. Do an IISRESET.

if you want to open an .msg file, or other file type saved in SharePoint without being asked to download it first; you just have to change the MIME type.
Like for .msg file $webApp.AllowedInlineDownloadedMimeTypes.Add("application/vnd.ms-outlook")

Hope that helps anyone out there.

No comments:

Post a Comment