SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to set some property bag values in SharePoint Online, specifically around SharePoint Designer access. The code below runs without error, but I do not see the propertybag value being updated in /_layouts/15/SharePointDesignerSettings.aspx. Is it not possible to update PropertyBag values in SharePoint Online?

$SiteUrl = "https://tenant.sharepoint.com/teams/eric"
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)
$web = $context.Site.RootWeb
$props =  $web.AllProperties
$props.FieldValues["allowdesigner"] = 0
$web.Update()
$context.ExecuteQuery()
share|improve this question
up vote 9 down vote accepted

Works for me with a couple small changes. Instead of manipulating the FieldValues object, just manipulate the AllProperties object directly. Also, set the value to a string, not an int:

web.AllProperties["allowdesigner"] = "0";

Here's the full helper method I use:

public static void AddWebProperty(ClientContext ctx, string propertyName, string propertyValue)
{
    Web web = ctx.Web;
    ctx.Load(web);
    ctx.ExecuteQuery();

    web.AllProperties[propertyName] = propertyValue;
    web.Update();            
    ctx.ExecuteQuery();
}
share|improve this answer
    
I knew I was effing something up somewhere. Adapting this to the existing PowerShell I had then set the desired properties. – Eric Alexander Feb 16 at 14:34
2  
You don't need to load properties. It's just unnecessary traffic. – dstarkowski Feb 16 at 14:35
    
@dstarkowski I wasn't sure, and never bothered to verify. I've edited the post to remove that. Thank you. – Derek Gusoff Feb 16 at 14:49

Derek's answer solves problem for property bag in general, but there's also Site.AllowDesigner property you could use for your specific case.

share|improve this answer
    
Both great answers – Eric Alexander Feb 16 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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