예제 #1
0
        protected override void ExecuteCmdlet()
        {
            if (Keys != null && Keys.Count > 0)
            {
                CurrentWeb.RemovePropertyBagValue("vti_indexedpropertykeys");

                foreach (var key in Keys)
                {
                    CurrentWeb.AddIndexedPropertyBagKey(key);
                }
            }
        }
예제 #2
0
        protected override void ExecuteCmdlet()
        {
            try
            {
                if (!ParameterSpecified(nameof(Folder)))
                {
                    if (!Indexed)
                    {
                        // If it is already an indexed property we still have to add it back to the indexed properties
                        Indexed = !string.IsNullOrEmpty(CurrentWeb.GetIndexedPropertyBagKeys().FirstOrDefault(k => k == Key));
                    }

                    CurrentWeb.SetPropertyBagValue(Key, Value);
                    if (Indexed)
                    {
                        CurrentWeb.AddIndexedPropertyBagKey(Key);
                    }
                    else
                    {
                        CurrentWeb.RemoveIndexedPropertyBagKey(Key);
                    }
                }
                else
                {
                    CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl);

                    var folderUrl = UrlUtility.Combine(CurrentWeb.ServerRelativeUrl, Folder);
                    var folder    = CurrentWeb.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl(folderUrl));

                    folder.EnsureProperty(f => f.Properties);

                    folder.Properties[Key] = Value;
                    folder.Update();
                    ClientContext.ExecuteQueryRetry();
                }
            }
            catch (Exception ex)
            {
                if (ex is ServerUnauthorizedAccessException)
                {
                    if (CurrentWeb.IsNoScriptSite())
                    {
                        ThrowTerminatingError(new ErrorRecord(new Exception($"{ex.Message} Site might have NoScript enabled, this prevents setting some property bag values.", ex), "NoScriptEnabled", ErrorCategory.InvalidOperation, this));
                        return;
                    }
                    throw;
                }
                else
                {
                    throw;
                }
            }
        }
예제 #3
0
 protected override void ExecuteCmdlet()
 {
     if (!string.IsNullOrEmpty(Key))
     {
         if (List != null)
         {
             var list = List.GetList(CurrentWeb);
             if (list != null)
             {
                 list.AddIndexedPropertyBagKey(Key);
             }
         }
         else
         {
             CurrentWeb.AddIndexedPropertyBagKey(Key);
         }
     }
 }