Opening Office Documents in Client Application Instead of the Browser

At Sympraxis, we work with organizations in a wide variety of industries. That’s one of the reasons we love working with SharePoint and Office 365 – there are no vertical focuses required. Organizations of just about every size and shape use these platforms, which makes life much more interesting.

That said, people in different industries expect different capabilities in the Office applications. While the browser version of Word or Excel is more than adequate for many people, for some organizations who need the more complex capabilities the browser versions fall short. Unfortunately, it can be very simple things sometimes, like working with headers and footers in Word. The online version of Word just doesn’t do this well – yet.

In the cases where an organization chooses to stick with the desktop applications – either because of specific needs or just because change is hard – there are several ways to change the behavior of opening a document from a SharePoint Document Library.

The simplest approach is to just change the behavior through the Library Settings. In Advanced settings, you have three options:

  • Open in the client application 
  • Open in the browser 
  • Use the server default (Open in the browser)

The first two options are pretty self explanatory. The third is more complicated.

Note:

All of this applies to Office documents: Word, Excel, PowerPoint, etc. PDFs are a whole other ball of wax. I may address them in a future post, but know they are different.

The third option is the default, and if you haven’t made any other changes, it will read Use the server default (Open in the browser).

Use the server default

If you want documents in the specific Document Library to open in the client application – this means Word or Excel on your local machine – then you can select that and it’ll work.

Open in the client application

But this is a very local solution – it applies only to the one Document Library. If you want to open documents in the client applications more broadly, you’ll want to turn to some automation. That means PowerShell.

Here’s an example showing how you might change the setting for a Document Library to open documents in the client applications. The example does this for the Documents library in one site. Obviously, you could add an outer loop to apply the change to multiple sites. You could also change the Where-Object clause to change the setting in more than one Document Library in the site.

$siteURL = "https://mytenant.sharepoint.com/sites/siteName/" 
Connect-PnPOnline -Url $siteURL 

# Open documents on the client
$web = Get-SPWeb -site $siteURL
foreach ($spList in $web.Lists | Where-Object { $_.Title -eq 'Documents' } ) {
    $spList.DefaultItemOpen = [Microsoft.Sharepoint.DefaultItemOpen]::PreferClient
    $spList.Update()
}

In the example, I’m setting the DefaultItemOpen property to PreferClient. This means the documents will be opened in the client applications.

There are two important properties for each SharePoint Document Library. Because there are two of them, thinking it through is a little more complex.

  • DefaultItemOpen – The enumeration for this property is effectively boolean. It can either be Browser (1) or PreferClient (0)
  • DefaultItemOpenUseListSetting – This property can either be True or False (truly boolean).

These two properties are what allows us to have three settings using boolean values. (It’s not how I would have built things, but here we are.)

If DefaultItemOpenUseListSetting is True, then the first two options come into play for the Document Library.

  • Open in the client application 
  • Open in the browser 

If DefaultItemOpenUseListSetting is False, then the third option is used:

  • Use the server default (Open in the browser)

That third option can either be:

  • Use the server default (Open in the browser) or
  • Use the server default (Open in the client application)

How might that change, you might ask? Well, there’s another option available here. There’s a Site Collection Feature called Open Documents in Client Applications by Default. This is where the so-called “server default” value comes from. It’s not actually at the “server” level (I’d expected a Tenant or Farm level setting, but as far as I can determine, there isn’t one.), but at the Site Collection level. There *may* be a setting at the Web Application level in older (pre-2019) versions of SharePoint, but I haven’t confirmed this.)

Open Documents in Client Applications by Default

If you’ve activated this feature, you’ve said “I want all documents in the Site Collection to open in the client applications.” (Yes, that’s Site Collection, not Site or Web or Modern Site. A modern site is actually a Site Collection. Sigh.)

Let’s say either your users have set the Document library settings in the UI or you’ve run some PowerShell (like the example above) to change the setting in specific Document Libraries. Well, to clean things up, you need to toggle the DefaultItemOpenUseListSetting property back to False if you want ALL documents in ALL Document Libraries in the Site Collection to open in the client application. Otherwise, you might have a mix of:

  • Open in the client application 
  • Open in the browser 

This is the PowerShell to do this:

$siteURL = "https://mytenant.sharepoint.com/sites/siteName/" 
Connect-PnPOnline -Url $siteURL 

# Open documents on the client
$web = Get-SPWeb -site $siteURL
foreach ($spList in $web.Lists | Where-Object { $_.Title -eq 'Documents' } ) {
    $spList.DefaultItemOpenUseListSetting = [System.Booolean]::False
    $spList.Update()
}

Even better, what if you wanted to change the behavior across your farm or tenant? Well, you can enable the Open Documents in Client Applications by Default (aka OpenInClient) feature on all your Site Collections, should you so choose.

#Get all site collections of the web app and iterate through
$siteCollections = Get-SPSite -WebApplication $WebAppURL -Limit ALL

Foreach ($siteCollection in $siteCollections ) { 

    Write-Host "Working on site: $($siteCollection.Url)"

    # Connect to the Site Collection
    $site = Connect-PnPOnline -Url $siteCollection.Url  -ReturnConnection

    # Get the feature properties so we don't need to know the GUID
    $feature = Get-SPFeature | Where-Object { $_.DisplayName -eq 'OpenInClient' -and $_.CompatibilityLevel -eq 15 }

    # Enable the feature
    Enable-SPFeature -Identity $feature.Id -Url $site.Url;

}

If this all seems confusing, it is. If you’re an end user or site owner, the UI settings options probably make pretty good sense. If you’re a SharePoint admin, the PowerShell probably makes pretty good sense. (there are MANY particles out there about this from the admin perspective.)

But the tricky are is where those two camps need to communicate about all this. If you don’t ask for the right thing, you might not get the thing you want. You probably want to do one of the following:

  • Open documents in a specific Document Library in the client applications
  • Open the documents in a specific site in the client applications
  • Open the documents in the entire farm or tenant in the client applications

Time will go by and you may want to REVERT those decisions and:

  • Open documents in a specific Document Library in the browser
  • Open the documents in a specific site in the browser
  • Open the documents in the entire farm or tenant in the browser

The key here is to understand how the settings and the feature work together in order to be successful. If you’ve made choices out of concert with each other, you may end up with a mess of inconsistent behavior on your hands.

As with so many things, effective communications – from both sides! – are important to reach the mutual goals.

from Marc D Anderson’s Blog https://ift.tt/33fThXC
via IFTTT