SharePoint SE. Adding Document Library to Wiki Page (classic view) via script not showing as it did in 2016.

Greg Ogle 40 Reputation points
2025-11-11T13:41:09.5266667+00:00

I am upgrading to SE from 2016 and the script I used to add Document Library Web Parts (XsltWebPart) to pages is not working the same in SE. I've searched high and low, but I've had no success.

Related, if I add another web part manually, both will show.

Thanks.

Microsoft 365 and Office | SharePoint Server | Development
{count} votes

Answer accepted by question author
  1. Steven-N 15,555 Reputation points Microsoft External Staff Moderator
    2025-11-11T14:19:38.2533333+00:00

    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:

    1. The command you're using to add Document Library Web Parts (XsltWebPart) to pages."
    2. Are you specifying a ViewGuid or XmlDefinition in your script?
    3. 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 WikiField contains the required placeholder markup with a <div> whose id follows the pattern div_<GUID in D format>
    • The web part itself is added to the special wiki zone named wpz and uses a web part ID in the form g_<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.


2 additional answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-11T13:43:46.76+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    In SharePoint Server (SE), there have been significant changes in how web parts function compared to SharePoint 2016. The XsltListViewWebPart, which you may have used to add Document Libraries, is not supported in modern pages, and this could be the reason your script is not working as expected.

    Key Points to Consider:

    1. Classic vs. Modern Web Parts: In SharePoint 2016, you could use classic web parts like XsltListViewWebPart for adding Document Libraries. However, in SE, many classic web parts have been replaced or deprecated. The modern equivalent for displaying Document Libraries is the Document Library web part.
    2. Manual Addition: You mentioned that when you add another web part manually, both show up. This indicates that the page is capable of displaying multiple web parts, but the script you are using may not be compatible with the current SharePoint environment. Ensure that your script is targeting the correct web part types that are supported in SE.
    3. Custom Solutions: If you need functionality that is not provided by the modern web parts, consider creating a custom web part using the SharePoint Framework (SPFx). This allows you to build tailored solutions that can meet specific requirements that classic web parts used to fulfill.
    4. Script Adjustments: If you are using scripts to automate the addition of web parts, you may need to update your scripts to align with the new web part models and APIs available in SE. Review the documentation for any changes in the API calls or parameters that might affect how web parts are added to pages.
    5. Resources for Migration: To help with the transition from classic to modern web parts, you can refer to the migration guides and documentation provided by Microsoft. This will give you insights into how to effectively modernize your customizations and ensure compatibility with SE.

    In summary, the inability to add Document Libraries as you did in 2016 is likely due to the deprecation of the XsltListViewWebPart and the shift towards modern web parts. You may need to explore using the Document Library web part or create a custom solution to achieve your desired functionality.


    References:

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.