0

I am able to connect to a WikiLibrary using CSOM on SharePoint Online, but I would want to extract the html content for Wiki Pages under it. I expected it to be in "PublishingPageContent" property, but that property is not there. Here is my code:

context.Credentials = new SharePointOnlineCredentials("xxx@xyz.onmicrosoft.com", password);
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
List docList = web.Lists.GetByTitle("WikiDocuments");
context.Load(docList);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View Scope='RecursiveAll'></View>";
ListItemCollection listCol = docList.GetItems(camlQuery);
ListItemCollection items = listCol;
context.Load(items, icol => icol.Include(i => i["PublishingPageContent"]));
context.ExecuteQuery();
string html;
foreach (ListItem item in items)
{
    File file = item.File;
    var wikiItem = file.ListItemAllFields;
    context.Load(wikiItem);
    context.ExecuteQuery();
    html = wikiItem["PublishingPageContent"].ToString();
}
1

I created a wiki pages library by adding an app > Wiki Page library.

Checked in the SPO wiki pages library, the content of the page resides in a field called Wiki Content whose internal name is WikiField which is of type Enhanced rich text.

So, you need to replace the PublishingPageContent with WikiField and it will be good to go. Also, no need to load the list item again inside the foreach loop as you have already included in the context.load.

Try the below sample code, works at my end.

ListItemCollection listCol = docList.GetItems(camlQuery);
ListItemCollection items = listCol;
context.Load(items, icol => icol.Include(i => i["WikiField"]));
context.ExecuteQuery();
string html;
foreach (ListItem item in items)
{
    html = Convert.ToString(item["WikiField"]);
    Console.WriteLine(html);
}

Check the below screenshot from a console application

enter image description here

| improve this answer | |

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.