On SharePoint 2013 search result page there is a "Preference" menu where the current user can for example change default behaviour how documents should be opened (client application or web-browser).

This setting will override any open-behaviour specified in Central Admin or Site Collection.

Is there a way to set this globally for all users, with powershell for example? To push out this change so that all users has the same default setting.


Found part of the solution needed for your problem in a blog comment by some guy named Marcus (http://www.sharepointblogs.be/blogs/vandest/archive/2014/03/26/sharepoint-2013-search-open-in-client.aspx):

private void EnsureOpenInClient()
    UserPreference preference = UserPreference.GetUserPreference();
    if (!preference.IsSettingEnabled(UserPreference.Settings.OpenDocumentsInClient))

According to MSDN it looks like the code always runs in the context of the current user but there is an overload where a context can be passed: https://msdn.microsoft.com/en-us/library/office/jj276799.aspx

So I think it should be able to add some impersonation code first like this:

using Microsoft.Office.Server.Search.Administration;

// replace domain and username to your needs or get a list of all users from somewhere (e.g. web.AllUsers)
SPUser user = web.EnsureUser("Domain\username");
SPSite impSite = new SPSite(siteURL, user.UserToken);
SPWeb impWeb = impSite.OpenWeb();

// Get contex from impersonated user and use that to get preferences
var ctx = SPContext.GetContext(impWeb);
UserPreference preferenceInContext = UserPreference.GetUserPreference(false, ctx);

// change settings of user
if (!preferenceInContext.IsSettingEnabled(UserPreference.Settings.OpenDocumentsInClient))

Haven't tested this myself yet!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.