Keith Smith - My Blog

fix for pdf and browser - run from SharePoint Management Shell

Wednesday, April 19, 2017 - by Keith A. Smith

Need to run PDF in the browser? Run the following in the sharepoint powershell

$webApp = Get-SPWebApplication http://host.domain.org
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 "Added and saved."
} Else {
  Write-Host -ForegroundColor White "Pdf MIME type is already added."
}


Other commands that may fix it if the above doesn’t :

Web Application level setting: Method 2
$webApp = Get-SPWebApplication http://intranet.domain
$webApp.BrowserFileHandling = "permissive"
$webApp.update()


Site Collection level
$site = get-spsite "http://intranet.domain/sites/somesite"
foreach ( $subsite in $site.allwebs )
{
 foreach ($list in $subsite.Lists)
 {
  if($list.browserfilehandling -eq "Strict")
  {
   $list.browserfilehandling = "Permissive";
   $list.update();
  }
 }
}


Site level ( SPWeb )
$web = Get-SPWeb "http://intranet.domain/sites/somesite/someweb"
foreach ($list in $web.Lists)
{
 if($list.browserfilehandling -eq "Strict")
 {
  $list.browserfilehandling = "Permissive";
  $list.update();
 }
}

List Level
$web= Get-SPWeb "http://intranet.domain/sites/somesite/someweb"
$list = $web.Lists["MyList"]
if($list.browserfilehandling -eq "Strict")
{
 $list.browserfilehandling = "Permissive";
 $list.update();
}

-End
  Share Post   

View Comments Comments


Leave a Comment