SharePoint Online: Open Documents in Client Applications by Default

Requirement: Open documents in client applications by default in SharePoint Online.

How to Open Documents in Client Application in SharePoint Online?
By default, documents such as Word, Excel, PowerPoint opens in browser with Office web apps in SharePoint Online. However, the office web applications like Word online doesn't gives you full functionality as in client installed application. So, if you want to change this behavior at site collection level, You have to activate a feature called "Open Documents in Client Applications by Default". Here is how to activate the feature:
  • Go to Site Settings >> Site Collection Features
  • Click on "Activate" button next to "Open Documents in Client Applications by Default" feature
    sharepoint online powershell open in client application
Activating the feature to open documents in client application for a single site collection is straight forward. How about activating the feature for all site collections?

SharePoint Online: PowerShell to Activate "Open in client application" Feature for All Sites
When the "Open Documents in Client Applications by Default" feature is activated, Office documents will open in the Office client application by default. E.g. a Excel spreadsheet  will open in Microsoft Excel installed on the client computer. When this feature is deactivated, a Excel Spreadsheet will open in Office Web Applications within the web browser. Here is the PowerShell to set open documents in client application settings for all site collections in a tenant by activating the feature discussed above. 
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Function to Activate Feature in SharePoint Online
Function Activate-SPOFeature
{ 
    Param ($SiteURL,$FeatureGuid)
    Try 
    {     
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credential.Username, $Credential.Password)
        $Ctx.Credentials = $Credentials
        $Site=$Ctx.Site
 
        #Get the Feature 
        $Feature =  $Site.Features.GetById($FeatureGuid)
        $Ctx.Load($Feature)
        $Ctx.ExecuteQuery()
 
        #Activate the feature if its not activated already
        Write-Host "Activating Feature $($FeatureStatus.DisplayName) in Site $SiteURL"
        if($Feature.DefinitionId -eq $null)
        {
            #sharepoint online powershell open in client application
            $Site.Features.Add($FeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null
            $Ctx.ExecuteQuery()
            Write-Host "`t Feature Activated!" -ForegroundColor Green
        }
        else
        {
            Write-host "`t Feature is Already Active on the Site collection!" -ForegroundColor Yellow
        }
    } 
    Catch
    {
        write-host "Error Activating Feature: $($_.Exception.Message)" -foregroundcolor Red
    }
}

#Parameters to Activate Feature
$AdminSiteURL = "https://Crescenttech-admin.sharepoint.com/"
$FeatureGuid= [System.Guid] ("8a4b8de2-6fd8-41e9-923c-c7c3c00f8295")

#Get Credentials to connect
$Credential = Get-Credential

#Connect To SharePoint Online Admin Center
Connect-SPOService -URL $AdminSiteURL -Credential $Credential
 
#Get All Site collection and loop through
ForEach($Site in (Get-SPOSite -Limit ALL))
{
    #Activate Feature
    Activate-SPOFeature -Site $Site.URL -FeatureGuid $FeatureGuid
}

SharePoint Online: Configure Open in Client Application at Document Library Level
In SharePoint Online, you can configure the open document in browser or client application setting from document library's settings.
  • Navigate to the Document Library >> Click on Settings gear >> Library Settings from the menu.
  • Under General Settings, Click on "Advanced Settings" link
  • Under "Opening Documents in the Browser", choose "Open in the client application" or " Open in the browser" according to your requirement.
    sharepoint online open documents in client applications by default
This overrides the setting applied at site collection level and open documents in client application instead of browser.
SharePoint Online: Open Documents in Client Applications by Default SharePoint Online: Open Documents in Client Applications by Default Reviewed by Salaudeen Rajack on March 20, 2018 Rating: 5

2 comments:

  1. This script has just what we need (and seems to be the only one with the solution) but when we run it we get this error on every site: Error Activating Feature: Exception calling ".ctor" with "2" argument(s): "The 'username' argument cannot be null.
    Parameter name: username". Has something in SharePoint Online changed since this script was created?

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.