Hi Greg Ogle
Thank you for reaching out to Microsoft
To assist you better and to accurately identify the issue you're encountering, could you please help by providing the following information:
- The command you're using to add Document Library Web Parts (
XsltWebPart) to pages." - Are you specifying a
ViewGuidorXmlDefinitionin your script? - Are you targeting a modern or classic page?
I am looking forward to hearing from you
After discussing some more information, here is the answer to this question:
Based on my research, as stated in this document, it seems like the root cause is on classic wiki pages, a list (XsltListViewWebPart) doesn’t render unless two conditions are met:
- The page’s
WikiFieldcontains the required placeholder markup with a<div>whose id follows the patterndiv_<GUID in D format> - The web part itself is added to the special wiki zone named
wpzand uses a web part ID in the formg_<GUID with underscores>.
In 2016 your script likely wrote correct placeholder HTML or the page already had it; in SE your current string "placeholder div" does not create the required <div id="div_...">, and your web part ID is not in the g_... format. As a result, the web part is present but has nowhere to render until a manual addition inserts proper wiki markup explaining why both parts show after you add one by hand.
Therefore, you can try the approach methods below to see if it can resolve your problem:
1. Insert correct placeholder markup in WikiField
Ensure the page’s WikiField contains the required <div> placeholder with id="div_<GUID>" and vid_<GUID> tags.
Without this markup, the web part has nowhere to render.
For example:
HTML
<div class='ms-rtestate-read ms-rte-wpbox' contentEditable='false'>
<div class='ms-rtestate-read {GUID}' id='div_{GUID}'></div>
<div style='display:none' id='vid_{GUID}'></div>
</div>
2. Use correct Web Part ID pattern and zone
Generate the web part ID in the format g_<GUID_with_underscores> and add it to the wpz zone.
PowerShell
$wpId = "g_" + $storageKey.ToString().Replace("-", "_")
$pwpmgr.AddWebPart($webpart, "wpz", 0)
Link instruction: https://sharepoint.stackexchange.com/questions/223257/adding-webparts-on-a-wiki-page-in-sharepoint-online-through-csom-and-powershell
Note: Microsoft is providing this information as a convenience to you. These sites are not controlled by Microsoft, and Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please ensure that you fully understand the risks before using any suggestions from the above link.
3. Use the correct ID patterns and zone
Generate a storage GUID and set the web part ID to g_<guid_with_underscores>; add it to zone wpz.
Example:
PowerShell
$storageKey = [Guid]::NewGuid()
$wpId = "g_" + $storageKey.ToString().Replace("-", "_")
$pwpmgr.AddWebPart($webpart, "wpz", 0)
$pwpmgr.SaveChanges($webpart)
Link reference: https://dori-uw-1.kuma-moon.com/en-us/previous-versions/office/developer/sharepoint-2010/ff806162%28v=office.14%29
Best regards
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.