1

I have set the AuthorizationFilter using the web interface, and successfully read the value.

  File file = context.Web.GetFileByServerRelativeUrl(url);
  LimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
  context.Load(wpm.WebParts,
  wps => wps.Include(
  wp => wp.WebPart.Title));
  context.ExecuteQuery();
  foreach (WebPartDefinition wpd in wpm.WebParts)
  {
      WebPart wp = wpd.WebPart;
      if (wp.Title == webPartTitle)
      {
          var properties = wp.Properties;
          context.Load(properties);
          context.ExecuteQuery();
          return properties.FieldValues;
      }
  }

The property values returns AuthorizationFilter=';;CN=MyGroupName,OU=SomeOu,OU=SomeOtheOu,DC=company,DC=com;;'

If I clear the AuthorizationFilter in the web interface and try to set the identical value using the following code, I get an exception "Exception has been thrown by the target of an invocation." If I set other properties, no exception is thrown and the respective property is updated.

  File file = context.Web.GetFileByServerRelativeUrl(url);
  LimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
  context.Load(wpm.WebParts,
  wps => wps.Include(
  wp => wp.WebPart.Title));
  context.ExecuteQuery();
  foreach (WebPartDefinition wpd in wpm.WebParts)
  {
      WebPart wp = wpd.WebPart;
      if (wp.Title == webPartTitle)
      {
          wp.Properties["AuthorizationFilter"] = ";;CN=MyGroupName,OU=SomeOu,OU=SomeOtheOu,DC=company,DC=com;;";
          wpd.SaveWebPartChanges();
          context.ExecuteQuery();  // this throws an Exception
          break;
      }
 }

Any help would be appreciated.

0

I found the source of the problem. The context address used did not exactly match the url containing the WebPart

so this combination throws the exception

string contextAddress = "http://spserver.company.com/"
string url = "http://spserver.company.com/SomeWeb/SitePages/Homepage.aspx"

while this combination works fine

string contextAddress = "http://spserver.company.com/SomeWeb/"
string url = "http://spserver.company.com/SomeWeb/SitePages/Homepage.aspx"

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.