Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Retrieve Wiki WebPart ID Property through CSOM

$
0
0

I currently have a wiki page with content as well as several script editor web parts spaced throughout. I am attempting to get all content from the wiki page in order throught the SharePoint CSOM. When grabbing the WikiField content I can see where each of the script editor web parts are placed because they have a DIV element with a GUID

<div class="ms-rtestate-read ms-rte-wpbox" contenteditable="false">
<div class="ms-rtestate-notify ms-rtestate-read 62f32861-7a85-489b-b92f-1784d7e758c9" id="div_62f32861-7a85-489b-b92f-1784d7e758c9" unselectable="on">
</div>
<div id="vid_62f32861-7a85-489b-b92f-1784d7e758c9" unselectable="on" style="display: none;">
</div>
</div>

The problem is that the GUID in the WikiField content is the web part id property while it seems that I can only retrieve the WebPartDefinition ID through CSOM, which is different. I need to find a way to match up the GUID in the WikiField content with the GUID in the WebPartDefinition WebPart so that I can grab the content from the manager and place it in the correct spot on the wiki page. There doesn't seem to be a WebPartDefinition.WebPart.ID property in the SharePoint CSOM.

So far my code is:

Public Function GetWiki(ByVal pSPSite As String, ByVal pLibraryName As String, ByVal pItemId As Int32) As Boolean
        Dim context As New ClientContext(pSPSite)
        Dim WikiLibrary As List = context.Web.Lists.GetByTitle(pLibraryName)
        Dim listItem As ListItem = WikiLibrary.GetItemById(pItemId)
        Dim wikiPage As File = listItem.File

        Try
            context.Load(wikiPage)
            context.Load(listItem)
            context.ExecuteQuery()

            Dim WikiContent As String = listItem("WikiField")

            Dim wpm As LimitedWebPartManager = wikiPage.GetLimitedWebPartManager(PersonalizationScope.Shared)
            context.Load(wpm.WebParts, Function(wps) wps.Include(Function(wp) wp.WebPart.Properties, Function(wp) wp.Id))

            context.ExecuteQuery()

            'Retrieve Script Web Parts added to Wiki Page
            For Each wpd As WebPartDefinition In wpm.WebParts
                Dim wpContent As String = wpd.WebPart.Properties("Content")
                Dim wpTitle As String = wpd.WebPart.Properties("Title")
            Next

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>