79602724

Date: 2025-05-02 02:09:02
Score: 0.5
Natty:
Report link

Ok, it is not quite an answer to the question but a work around that got me past the error.

My issue is that the Content Type was available in the Content type hub and I needed to sync from there.

string rootUrl = webURL.Substring(0, webURL.IndexOf("/", 8));

ClientContext clientContext2 = Task.Run(() => AuthManager.GetContextAsync(rootUrl).GetAwaiter().GetResult()).Result;

clientContext2.ExecutingWebRequest += delegate (object senderCC, WebRequestEventArgs eCC)
{
    eCC.WebRequestExecutor.WebRequest.UserAgent = "NONISV|EncompaaS|OricaConnector/1.0";
};

var web2 = clientContext2.Site.RootWeb;
clientContext2.Load(web2, w => w.AvailableContentTypes);
clientContext2.ExecuteQuery();
var ctype = web2.AvailableContentTypes.First(c => c.Name == ContentType);

var sub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypeSubscriber(clientContext);
clientContext.Load(sub);
clientContext.ExecuteQuery();
sub.SyncContentTypesFromHubSite2(webURL, new List<string>() { ctype.Id.StringValue });
clientContext.ExecuteQuery();

list.AddContentTypeToListByName(ContentType);
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Tony C