Unable to open PDF/HTML/XML files directly in a browser in SharePoint 2010? The default configuration of SharePoint 2010 does not consider PDF documents safe for displaying in the browser. This script adds a new MIME type to the "AllowedInlineDownloadedMimeTypes" property list of the defined SharePoint.
Method 1
- Open the SharePoint Central Administration.
- Select "Application Management".
- Click on "Manage Web Applications".
- Select Particular Web Application .
- Got Ribbon and Select General Settings
- In the Browser File Handling section:
- Select "Permissive" and click "Ok".
- Clear the Browser Cache and open the PDF.
Method 2
Without changing the Web Application Settings (in other words Permissive and Strict).
This script adds a new MIME type to the "AllowedInlineDownloadedMimeTypes" property list of the defined SharePoint 2010 Web Application.
The script prompts you for the MIME type (for example application/pdf, text/html, text/xml) and Web Application URL.
The code shall run in the context of the Farm Administrators group member.
# <#
# .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 "`nEnter Web Application URL")
Write-Host `n"Mime Type Examples:"`n"application/pdf, text/html, text/xml"`n
If ($WebApp.AllowedInlineDownloadedMimeTypes -notcontains ($MimeType = Read-Host "Enter a required mime type"))
{
Write-Host -ForegroundColor White `n"Adding" $MimeType "MIME Type to defined Web Application"$WebApp.url
$WebApp.AllowedInlineDownloadedMimeTypes.Add($MimeType)
$WebApp.Update()
Write-Host -ForegroundColor Green `n"The" $MimeType "MIME type has been successfully added."
} Else {
Write-Host -ForegroundColor Red `n"The" $MimeType "MIME type has already been added."
}