SharePoint - Document Library Content Search Box on Custom Page

Sanjay Adsure 1 Reputation point
2025-03-28T11:31:43.4766667+00:00

Dear All,

In SharePoint modern view, when open any library, we get 'Search Box' on our left side or top bar which says 'Search in this Library...' and it searches for content of this document library. It also searches for document content which is actually important for us here.

Can I reuse this Search Box on a custom page where I'm having other custom things, this Search Box & below that Library web part showing any view of that library. When user will come to this page & search something it should filter the already existing library with that search results like it does on OOTB AllItems.aspx page?

Or can we customize AllItems.aspx page to add any custom web part so I can use that page?

Thanks,

Sanjay

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,548 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,426 Reputation points Microsoft External Staff
    2025-03-31T02:10:07.7366667+00:00

    Hi @Sanjay Adsure,

    For content-based search matching the OOTB experience:

    Use PnP Modern Search if you need a balance of customization and effort.

    Use OOTB Search Results Web Part if minor UI differences are acceptable.

    For metadata-only filtering, use the query string method with the library web part.

    1. Install the PnP Modern Search solution.
    2. Add the Search Box web part to your custom page.
    3. Add the Search Results web part and configure it:
      • Under Query, use {searchTerms} Path:"https://yourtenant.sharepoint.com/sites/yoursite/YourLibrary".
      • Customize the results template to match your library’s columns.
    4. Connect the Search Box to the Search Results web part via dynamic data connections

    Modern SharePoint library pages (like AllItems.aspx) are not editable. You cannot add custom web parts to them. Instead, create a new page and use the above approaches.


    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.


Your answer

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