01 April 2011

open pdf files in browser

Open PDF files in browser in Sharepoint 2010


Web Application level setting: Method 1 (UI)

• Go to SharePoint 2010 Central Administration > Application Management > Manage Web Applications
• Select the row of your web application
• Click General Settings in the ribbon
• Scroll down to Browser File Handling and select Permissive
• Click Ok

Web Application level setting: Method 2

$webApp = Get-SPWebApplication http://intranet.domain
$webApp.BrowserFileHandling = "permissive"
$webApp.update()

Web Application level setting: Method 3 (recommended)

$webApp = Get-SPWebApplication http://intranet.domain
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."
}

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(); 
} 

2 comments:

  1. Thanks for the solution. As a newbie it will be very helpful to know which file this code belongs to or should be updated at.
    Instructions on where to edit/run the code along with the code always helps.

    Much Appreciated.

    Thanks
    Mandeep

    ReplyDelete