0

I am using the SharePoint Online CSOM library to change an ImageLink property in a WebPartPage. I first check-out the page, make any changes, and then check-in the page. When I check-in the page, the page's content type shown in SharePoint Online changes from "Web Part Page" to "Wiki Page". If I re-read the page, the ListItem's ContentType field is indeed set to a Wiki page ID ("0x0101080091497901794A9E4E8282666A11DAE0AD"). I'm stumped as to what is causing this.

Here's my C# code:

using (SP.ClientContext context = SharePoint.GetClientContext(site.Url, siteCollection))
{
    string serverRelativeUrl = site.GetServerRelativeUrl(url);
    SP.File csomFile = context.Web.GetFileByServerRelativeUrl(serverRelativeUrl);
    context.Load(csomFile);
    context.ExecuteQueryWithRetry();

    LimitedWebPartManager limitedWebPartManager = csomFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
    context.Load(limitedWebPartManager);
    WebPartDefinitionCollection webPartDefinitionCollection = limitedWebPartManager.WebParts;
    context.Load(webPartDefinitionCollection, wpdc => wpdc.Include(
        wpd => wpd.Id,
        wpd => wpd.WebPart,
        wpd => wpd.WebPart.Properties));
    context.ExecuteQueryWithRetry();

    bool pageChanged = false;
    bool webPartChanged = false;
    foreach (WebPartDefinition wpd in webPartDefinitionCollection)
    {
        string imageLinkUrl = wpd.WebPart.Properties.GetField<string>(@"ImageLink");
        if (!String.IsNullOrEmpty(imageLinkUrl))
        {
            bool linkChanged = LinkHandler(ref imageLinkUrl);
            if (linkChanged)
            {
                wpd.WebPart.Properties[@"ImageLink"] = imageLinkUrl;
                webPartChanged = true;
            }
        }

        if (webPartChanged)
        {
            wpd.SaveWebPartChanges();
            pageChanged = true;
        }
    }

    if (pageChanged)
    {
        context.ExecuteQueryWithRetry();
    }
}

Update: I have also discovered that if I manually check-out and check-in the file (or discard check-out) from a browser, the content type is also changed to a Wiki Page. Is this normal behavior?

Your Answer

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

Browse other questions tagged or ask your own question.