public void AddHtmlToWikiPage(string html, int row, int col, bool prepend = false) { // Reference code - OfficeDevPnP: https://github.com/OfficeDev/PnP/blob/master/OfficeDevPnP.Core/OfficeDevPnP.Core/AppModelExtensions/PageExtensions.cs string wikiField = (string)ListItemAllFields["WikiField"]; XmlDocument xd = new XmlDocument(); xd.PreserveWhitespace = true; xd.LoadXml(wikiField); // Sometimes the wikifield content seems to be surrounded by an additional div? XmlElement layoutsTable = xd.SelectSingleNode("div/div/table") as XmlElement; if (layoutsTable == null) { layoutsTable = xd.SelectSingleNode("div/table") as XmlElement; } // Add the html content XmlElement layoutsZoneInner = layoutsTable.SelectSingleNode(string.Format("tbody/tr[{0}]/td[{1}]/div/div", row, col)) as XmlElement; if (layoutsZoneInner == null) { throw new ArgumentException("Unable to locate row and/or column to insert HTML into."); } XmlText text = xd.CreateTextNode("!!123456789!!"); if (prepend) { layoutsZoneInner.PrependChild(text); } else { layoutsZoneInner.AppendChild(text); } ListItemAllFields["WikiField"] = xd.OuterXml.Replace("!!123456789!!", html);; ListItemAllFields.Update(); }
public void AddHtmlToWikiPage(string html) { ListItemAllFields["WikiField"] = html; ListItemAllFields.Update(); }