How do I add a webpart to a library view? Or make a library webpart follow deep links?

Paul Rowe 20 Reputation points
2025-11-17T17:42:43.5666667+00:00

Current Situation

I have a document library that uses the Classic experience. This is necessary because the page includes a custom webpart that displays buttons based on the current user’s permissions and the document status (stored in a custom column). One or two buttons may be displayed next to each file (buttons are not shown for folders) and a button may be displayed just below the folder contents. If the user is at the top level of the library, a warning message is displayed: “Don’t store files at the top level.”

Clicking the button displayed below the folder contents displays a modal dialog box. The dialog box includes a textarea and two buttons: “Send Email” and “Cancel”. Clicking the button labeled “Send Email” would send an email to the programmatically determined recipients with a link to the folder the user was browsing when they clicked the “Send Email” button. Clicking the button labeled “Cancel” would dismiss the modal without further action.

Current Issue

The code is using the SharePoint SendMail REST API endpoint to send the email. That endpoint now returns an error with a note prompting the developer to use the Graph API instead. The emails are not being sent anymore.

Potential Solutions

I have set up custom formatting to display the buttons for each row when I switch the library to use the Modern experience. I have also developed a SharePoint Framework webpart that, when shown on the same page with the library webpart, controls the visibility of those buttons based on the current user’s group membership. The webpart now uses the Graph API to send email.

I am investigating two paths forward but have hit a wall in both directions.

  • Can I show the SPFx webpart at the top of the default library view? I have looked, but I cannot find a way to do that. This would allow me to deploy the SPFx webpart as is.
  • Can I specify a deep link to a custom webpart page such that the library webpart would be directed to a subfolder specified in the query string? I am open to building a modern page that includes the custom webpart and the library webpart, but don’t know how to specify that deep link or forward it from my SPFx webpart to the library webpart.
Microsoft 365 and Office | SharePoint | Development
{count} votes

Answer accepted by question author
  1. Teddie-D 8,640 Reputation points Microsoft External Staff Moderator
    2025-11-18T04:04:03.0133333+00:00

    Hi @Paul Rowe 

    Thank you for posting your question in the Microsoft Q&A forum. 

    You can’t place a web part directly on the Modern library view page (…/Forms/AllItems.aspx). Modern library pages (default list/library view pages) are system pages; you cannot add regular SPFx web parts to them. Web parts only work on editable pages (modern site pages), not the built-in library view.  

    Supported alternatives:  

    1.SPFx Application Customizer  

    -You can inject your UI (buttons, modals, warnings) at the top of the page using the Top placeholder.  

    -Works on library pages themselves, so users stay in the library.  

    -Can read the current folder from RootFolder or id in the URL and handle logic like showing buttons per folder.  

    Note: On modern library pages, RootFolder may not always be present when navigating between folders without refreshing, so fallback detection may be required. 

    -Reference: Use page placeholders from Application Customizer (Hello World part 2) | Microsoft Learn

    2.ListView Command Set  

    -Adds item-level or row-level buttons directly to the library toolbar/context menu.  

    -Ideal if your buttons are per file/folder.  

    -Reference: Build your first ListView Command Set extension | Microsoft Learn

    The Document Library web part can be configured to open a specific folder, but this is controlled through a static setting in the web part’s properties. Once configured, the folder path remains fixed, and there is no supported query‑string parameter that allows the embedded web part to dynamically open a different folder at runtime. 

    However, modern library pages support direct deep links to folders. For example, you can navigate directly to a subfolder using a URL such as: /sites/SiteA/Shared Documents/Forms/AllItems.aspx?id=/sites/SiteA/Shared Documents/FolderA/SubfolderB. This approach works when users go directly to the library view page itself. It does not apply when the library is embedded as a web part on another modern page, since in that scenario the folder setting remains static and cannot be changed through the URL. 

    I hope this information is helpful. 


    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.  


0 additional answers

Sort by: Most helpful

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.