Pages

Search This Blog

Tuesday, January 17, 2012

Open PDF files directly in browser SharePoint 2010

Here is how you can tell SharePoint 2010 site to open the PDF files in the browser instead of prompting the user to save or open the PDF. This will be a great option to the most of end users. This needs simple Powershell scripting run on the server. Below is the code we should use:



# <# 
# .DESCRIPTION 
#  This script adds new MIME type to "AllowedInlineDownloadedMimeTypes" property list of defined SharePoint 2010 Web Application.
#
#  Script prompts you for MIME type and Web Application URL.
#
#  Code shall run in context of Farm Administrators group member.


If ( (Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null ) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
Get-SPWebApplication
$WebApp = Get-SPWebApplication $(Read-Host "Enter Web Application URL")
Write-Host "Mime Type Examples:""application/pdf, text/html, text/xml"


If ($WebApp.AllowedInlineDownloadedMimeTypes -notcontains ($MimeType = Read-Host "Enter a required mime type"))
{
  Write-Host -ForegroundColor White "Adding" $MimeType "MIME Type to defined Web Application"$WebApp.url
  $WebApp.AllowedInlineDownloadedMimeTypes.Add($MimeType)
  $WebApp.Update()
  Write-Host -ForegroundColor Green "The" $MimeType "MIME type has been successfully added."
} Else {
  Write-Host -ForegroundColor Red "The" $MimeType "MIME type has already been added."
}

No comments:

Post a Comment