Navigate OneDrive data with Microsoft Graph and Mgt-File-List Beta version

Published 05-06-2021 02:36 PM 1,478 Views
Senior Member

In my process of self learning regarding different technologies such us Azure, SPFX WebPart, React, Microsoft Graph, Node.js, Teams and all other Office 365 services, was surprise to find the current work already made by "Microsoft Graph Toolkit" and associated documentation on how to implemented with Microsoft Graph.

The amount of content and features already develop to integrate multiple platforms are definitely the Key to communicate with Office 365 and became easy to access content without a lot of effort, congrats to all the team.

 

This sample use SharePoint Online SPFX WebPart with Mgt-File-List and Mgt-File Beta version control to retrieve Shared Libraries as existing in OneDrive, navigate between their folders and use filter by file extension in a simple way using Microsoft Graph API Drive and Site.

 

Below a draw resuming the custom query's made and what control uses to retrieve associated folders and files from different locations.

MainCalls.png

How the Mgt-File-List Work

 

As OneDrive, this control allow to display Shared Files and Folders, for this ItemID (identity of the item to read, can be a folder or a file) has the main role on how to access content. To facilitate this access the control has multiple properties that allows call to content using different options such us: custom query's (file-queries) or pre defined query's (insight-type="shared").

This sample used the parameters SiteID (SharePoint Online Site ID) and ItemID it's the ID of the root Library used on site to store documents and control to display files/folders from that Path and navigate between them.

Solution also uses the property File-List-Query that allows to search files inside shared Libraries.

<FileList
        siteId={this._siteID}
        itemId={this._itemID}
></FileList>

 

Where can I found SiteID of a site?

 

Use the Site Graph API with search query based on hostname to retrieve ID's of sites.

"https://graph.microsoft.com/v1.0/sites?search=*****.sharepoint&$Select=id"
List of Site ID's:
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites(id)",
    "value": [
        {
            "id": "*******.sharepoint.com,000000-0000-0000-0000-000000,000000-0000-0000-0000-000000"
        },
        {
            "id": "*******.sharepoint.com,000000-0000-0000-0000-000001,000000-0000-0000-0000-000001"
        },
...

 

How can I found the Root Folder ItemID from Site?

 

This can be achieved using the SiteID from last query and call the drive root from Site.

https://graph.microsoft.com/v1.0/sites/*****.sharepoint.com,000000-0000-0000-0000-000000,000000-0000-0000-0000-000000/drive/Root?$select=id

This query returns the Item-id of the root Folder that can be used to display content in Control.

"id": "01CM5BY6********************************"

 

Retrieve OneDrive Root Folder Item-id

 

OneDrive is managed differently and there is no need of SiteID just make the following Drive call.

https://graph.microsoft.com/v1.0/me/drive/root/?$Select=id

PS: This query's can be tested using the following site.

https://developer.microsoft.com/en-us/graph/graph-explorer

Below some additional Mgt-File-List documentation regarding possible options to use.

This main query will allow to fully explore the Mgt-File-List features that were used in sample "react-oneDrive-finder"

  • List of Drives Sites
  • Content List and Breadcrumb
  • Filter of Items
  • Filter by file extension
  • Custom Theme styles 

SampleFileList.png

Mgt provider and SharePointProvider

 

It's important that permissions are given from Microsoft Graph to SPFX WebPart that Mgt-File-List could make the necessary query's.

Access to config/package-solution.json and ensure the following permissions are given on SharePoint package.

    "webApiPermissionRequests": [{  
      "resource": "Microsoft Graph",  
      "scope": "Files.Read"  
  }, {  
      "resource": "Microsoft Graph",  
      "scope": "Files.Read.All"  
  }, {  
      "resource": "Microsoft Graph",  
      "scope": "Sites.Read.All"  
  }] 

Access to your code into BaseClientSideWebPart area and ensure SharePoint Provider is loaded with the current security  access that Mgt-File-List control and custom graph query's could access to Microsoft Graph content.

import { Providers, SharePointProvider } from '@microsoft/mgt';
...
export default class OneDriveFinderWebPart extends BaseClientSideWebPart<IOneDriveFinderWebPartProps> {
  protected onInit() {
    Providers.globalProvider = new SharePointProvider(this.context);
    return super.onInit();
  }
...

After defining the provider you should be able to include control and use parameter's id without permissions errors.

import { FileList } from '@microsoft/mgt-react';
...
<FileList
              siteId={this._siteID}
              itemId={this._itemID}
              itemClick={this.manageFolder}
            ></FileList>

 

Breadcrumb Navigation

 

It's also possible to use Breadcrumb to include the path of folders where user is situated in the Library.

This can be achieve capturing the itemID of Folder listed in Mgt-File-List, using the event "itemClick={(e)=>{ console.log(e.details);}". 

More information can be found on Mgt-File-List documentation or by sample "react-onedrive-finder".

 

Filtering file extensions

 

The Mgt-File-List property fileExtensions allows to filter documents by file extension, this can be very handy when dealing with large amounts of documents.

Code below shows how can be implemented a multiple file extensions filter.

 

 const checkFileExtensions = (event: React.FormEvent<HTMLDivElement>, selectedOption: IDropdownOption) => {
      let fileExtensions: string[] = [];
      if (selectedOption.selected == true) {
        fileExtensions.push(selectedOption.key.toString());
        fileExtensions = [...fileExtensions,...this.state.fileExtensions];
      } else {
        fileExtensions = this.state.fileExtensions.filter(e => e !== selectedOption.key );
      }
      this.setState({
        fileExtensions: [...fileExtensions]
      });
    };
.....
<Dropdown
	placeholder="Select"
	label="Select file extensions"
    multiSelect
    options={[
		  { key: "", text: 'folder' },
		  { key: "docx", text: 'docx' },
		  { key: "xlsx", text: 'xlsx' },
		  { key: "pptx", text: "pptx" },
		  { key: "one", text: "one" },
		  { key: "pdf", text: "pdf" },
		  { key: "txt", text: "txt" },
		  { key: "jpg", text: "jpg" },
		  { key: "gif", text: "gif" },
		  { key: "png", text: "png" },
		]}
	onChange={checkFileExtensions}
	styles={dropdownFilterStyles}
/>
...
<FileList
	fileExtensions={this._fileExtensions}
	...
/></FileList/>

 

Styling with Mgt-File-List

 

The Mgt-File-List includes Light and Dark theme but you can also provide your custom styles.

<FileList
    className="mgt-dark"
	...
></FileList>

To create your own custom style look and feel you can use css elements to customize Mgt-File-List.

Below some of the options available and shared in FileList Stories of the Beta Version.

.mgtfilelist {
  --file-list-background-color: #eff6fc;
  --file-item-background-color--hover: #deecf9;
  --file-item-background-color--active: #c7e0f4;
  --file-list-border: 0px solid #white;
  --file-list-box-shadow: none;
  --file-list-padding: 0px;
  --file-list-margin: 0;
  --file-item-border-radius: 0px;
  --file-item-margin: 0px 0px;
  --file-item-border-top: 1px solid #dddddd;
  --file-item-border-left: 1px solid #dddddd;
  --file-item-border-right: 1px solid #dddddd;
  --file-item-border-bottom: 1px solid #dddddd;
  --show-more-button-background-color: #fef8dd;
  --show-more-button-background-color--hover: #ffe7c7;
  --show-more-button-font-size: 14px;
  --show-more-button-padding: 16px;
  --show-more-button-border-bottom-right-radius: 12px;
  --show-more-button-border-bottom-left-radius: 12px;
}

 

Search in Shared Libraries

 

The control by the property "fileListQuery" also allow the usage Graph Drive Search method to find Items in the Drive. Below an sample on how you could use a dynamic to search items in Drives.

//Make query on Shared Library or OneDrive Library 
const checkSearchDrive = (SearchQuery: string) => {
      if (this.state.siteID != "") {
        this.setState({
          searchDrive: "/sites/" + this.state.siteID + "/drive/root/search(q='" + SearchQuery + "')"
        });
      } else {
        this.setState({
          searchDrive: "/me/drive/root/search(q='" + SearchQuery + "')"
        });
      }
    };
	
//Search Box for Shared Library 
<SearchBox placeholder="Search Drive" onSearch={checkSearchDrive} onClear={checkClear} />

//Display search content
{(this.state.searchDrive != "") &&
    <FileList
    fileListQuery={searchDrive}
	></FileList>
}

 

Final sample solution

 

Below the final result of the configuration of Mgt-File-List react controls:

OneDrivefinderSample3.gif

Solution can be found in the SharePoint Framework Client-Side Web Part Samples - OneDrive finder:

https://github.com/pnp/sp-dev-fx-webparts/tree/master/samples/react-onedrive-finder

PS: Solution will be updated with release version when Mgt-File-List is available by the Microsoft Graph Toolkit.

 

How to start with Microsoft Graph Toolkit and SharePoint Online

There is a very good articles on how to start for example, Build a SharePoint web part with the Microsoft Graph Toolkit

To use the Mgt-File-List control in Beta version please use the following packages.

npm i @microsoft/mgt@next
npm i @microsoft/mgt-react@next

PS: The Microsoft Graph Toolkit Team made available access to Beta version of Mgt-File-List and react. Final version package can be monitor and accessible in microsoft-graph-toolkit.

 

I will hope this article could help you onboard when the Mgt-File-List control becomes officially available.

 

Support Documentation:

%3CLINGO-SUB%20id%3D%22lingo-sub-2296730%22%20slang%3D%22en-US%22%3ENavigate%20OneDrive%20data%20with%20Microsoft%20Graph%20and%20Mgt-File-List%20Beta%20version%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2296730%22%20slang%3D%22en-US%22%3E%3CDIV%3E%0A%3CP%3EIn%20my%20process%20of%20self%20learning%20regarding%20different%20technologies%20such%20us%20Azure%2C%20SPFX%20WebPart%2C%20React%2C%20Microsoft%20Graph%2C%20Node.js%2C%20Teams%20and%20all%20other%20Office%20365%20services%2C%20was%20surprise%20to%20find%20the%20current%20work%20already%20made%20by%20%22%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20Graph%20Toolkit%3C%2FA%3E%22%20and%20associated%20documentation%20on%20how%20to%20implemented%20with%20Microsoft%20Graph.%3C%2FP%3E%0A%3CP%3EThe%20amount%20of%20content%20and%20features%20already%20develop%20to%20integrate%20multiple%20platforms%20are%20definitely%20the%20Key%20to%20communicate%20with%20Office%20365%20and%20became%20easy%20to%20access%20content%20without%20a%20lot%20of%20effort%2C%20congrats%20to%20all%20the%20team.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20sample%20use%20SharePoint%20Online%20SPFX%20WebPart%20with%20%3CSTRONG%3EMgt-File-List%20and%20Mgt-File%20Beta%20version%3C%2FSTRONG%3E%20control%20to%20retrieve%20Shared%20Libraries%20as%20%3CSTRONG%3Eexisting%20in%20OneDrive%3C%2FSTRONG%3E%2C%20navigate%20between%20their%20folders%20and%20use%20filter%20by%20file%20extension%20in%20a%20simple%20way%20using%20Microsoft%20Graph%20API%20Drive%20and%20Site.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20face%3D%22inherit%22%3EBelow%20a%20draw%20resuming%20the%20custom%20query's%20made%20and%20what%20control%20uses%20to%20retrieve%20associated%20folders%20and%20files%20from%20%3C%2FFONT%3Edifferent%3CFONT%20face%3D%22inherit%22%3E%26nbsp%3Blocations.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22MainCalls.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F276720i5A62C2F7948D668D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22MainCalls.png%22%20alt%3D%22MainCalls.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-2006179640%22%20id%3D%22toc-hId-2006179640%22%3EHow%20the%20Mgt-File-List%20Work%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20OneDrive%2C%20this%20control%20allow%20to%20display%20Shared%20Files%20and%20Folders%2C%20for%20this%20%3CSTRONG%3EItemID%20(identity%20of%20the%20item%20to%20read%2C%20can%20be%20a%20folder%20or%20a%20file)%3C%2FSTRONG%3E%20has%20the%20main%20role%20on%20how%20to%20access%20content.%20To%20facilitate%20this%20access%20the%20control%20has%20multiple%20properties%20that%20allows%20call%20to%20content%20using%20different%20options%20such%20us%3A%20%3CSTRONG%3Ecustom%20query's%3C%2FSTRONG%3E%26nbsp%3B(%3CSTRONG%3Efile-queries)%20%3C%2FSTRONG%3Eor%26nbsp%3Bpre%20defined%20%3CSTRONG%3Equery's%20(%3CSPAN%20class%3D%22pl-c1%22%3Einsight-type%3C%2FSPAN%3E%3CSPAN%3E%3D%22%3C%2FSPAN%3E%3CSPAN%20class%3D%22pl-s%22%3Eshared%3C%2FSPAN%3E%3CSPAN%3E%22%3C%2FSPAN%3E)%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3EThis%26nbsp%3Bsample%20used%20the%20parameters%20%3CSTRONG%3ESiteID%20%3C%2FSTRONG%3E(SharePoint%20Online%20Site%26nbsp%3BID)%20and%20%3CSTRONG%3EItemID%3C%2FSTRONG%3E%26nbsp%3Bit's%20the%20ID%20of%20the%20root%20Library%20used%20on%20site%20to%20store%20documents%20and%20control%20to%20display%20files%2Ffolders%20from%20that%20Path%20and%20navigate%20between%20them.%3C%2FP%3E%0A%3CP%3ESolution%20also%20uses%20the%20property%20%3CSTRONG%3EFile-List-Query%3C%2FSTRONG%3E%20that%20allows%20to%20search%20files%20inside%20shared%20Libraries.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CFILELIST%20siteid%3D%22%7Bthis._siteID%7D%22%20itemid%3D%22%7Bthis._itemID%7D%22%3E%3C%2FFILELIST%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--1598226182%22%20id%3D%22toc-hId--1598226182%22%3EWhere%20can%20I%20found%20SiteID%20of%20a%20site%3F%3C%2FH4%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUse%20the%26nbsp%3B%3CSTRONG%3ESite%20Graph%20API%20with%20search%3C%2FSTRONG%3E%20query%20based%20on%20hostname%20to%20retrieve%20ID's%20of%20sites.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fsites%3Fsearch%3D*****.sharepoint%26amp%3B%24Select%3Did%22%3C%2FCODE%3E%3C%2FPRE%3EList%20of%20Site%20ID's%3A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22%40odata.context%22%3A%20%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2F%24metadata%23sites(id)%22%2C%0A%20%20%20%20%22value%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22*******.sharepoint.com%2C000000-0000-0000-0000-000000%2C000000-0000-0000-0000-000000%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22*******.sharepoint.com%2C000000-0000-0000-0000-000001%2C000000-0000-0000-0000-000001%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A...%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-889286651%22%20id%3D%22toc-hId-889286651%22%3EHow%20can%20I%20found%20the%20Root%20Folder%20ItemID%20from%20Site%3F%3C%2FH4%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20can%20be%20achieved%20using%20the%20%3CSTRONG%3ESiteID%20%3C%2FSTRONG%3Efrom%20last%20query%20and%20call%20the%20drive%20root%20from%20Site.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fsites%2F*****.sharepoint.com%2C000000-0000-0000-0000-000000%2C000000-0000-0000-0000-000000%2Fdrive%2FRoot%3F%24select%3Did%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20query%20returns%20the%20%3CSTRONG%3EItem-id%3C%2FSTRONG%3E%20of%20the%20root%20Folder%20that%20can%20be%20used%20to%20display%20content%20in%20Control.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%22id%22%3A%20%2201CM5BY6********************************%22%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH4%20id%3D%22toc-hId--918167812%22%20id%3D%22toc-hId--918167812%22%3E%26nbsp%3B%3C%2FH4%3E%0A%3CH4%20id%3D%22toc-hId-1569345021%22%20id%3D%22toc-hId-1569345021%22%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3ERetrieve%20OneDrive%20Root%20Folder%20Item-id%3C%2FSTRONG%3E%3C%2FH4%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOneDrive%20is%20managed%20differently%20and%20there%20is%20no%20need%20of%20SiteID%20just%20make%20the%20following%20Drive%20call.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%2F%3F%24Select%3Did%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EPS%3A%20This%20query's%20can%20be%20tested%20using%20the%20following%20site.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fgraph%2Fgraph-explorer%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fgraph%2Fgraph-explorer%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EBelow%20some%20additional%20Mgt-File-List%20documentation%20regarding%20possible%20options%20to%20use.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%2Fblob%2Fmain%2Fspecs%2Fmgt-file-list.md%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EFileList%20specifications%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%2Fblob%2Fmain%2Fstories%2Fcomponents%2FfileList.stories.js%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EFileList%20Stories%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThis%20main%20query%20will%20allow%20to%20fully%20explore%20the%20%3CSTRONG%3EMgt-File-List%3C%2FSTRONG%3E%20features%20that%20were%20used%20in%20sample%20%22%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fsp-dev-fx-webparts%2Ftree%2Fmaster%2Fsamples%2Freact-onedrive-finder%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ereact-oneDrive-finder%3C%2FA%3E%22%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EList%20of%20Drives%20Sites%3C%2FLI%3E%0A%3CLI%3EContent%20List%20and%20Breadcrumb%3C%2FLI%3E%0A%3CLI%3EFilter%20of%20Items%3C%2FLI%3E%0A%3CLI%3EFilter%20by%20file%20extension%3C%2FLI%3E%0A%3CLI%3ECustom%20Theme%20styles%26nbsp%3B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SampleFileList.png%22%20style%3D%22width%3A%20664px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F278794i731EF796D5A52971%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SampleFileList.png%22%20alt%3D%22SampleFileList.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1558841917%22%20id%3D%22toc-hId-1558841917%22%3E%3CSTRONG%3EMgt%20provider%20and%20SharePointProvider%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt's%20important%20that%20permissions%20are%20given%20from%20Microsoft%20Graph%20to%20SPFX%20WebPart%20that%20Mgt-File-List%20could%20make%20the%20necessary%20query's.%3C%2FP%3E%0A%3CP%3EAccess%20to%20config%2Fpackage-solution.json%20and%20ensure%20the%20following%20permissions%20are%20given%20on%20SharePoint%20package.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%20%20%20%20%22webApiPermissionRequests%22%3A%20%5B%7B%20%20%0A%20%20%20%20%20%20%22resource%22%3A%20%22Microsoft%20Graph%22%2C%20%20%0A%20%20%20%20%20%20%22scope%22%3A%20%22Files.Read%22%20%20%0A%20%20%7D%2C%20%7B%20%20%0A%20%20%20%20%20%20%22resource%22%3A%20%22Microsoft%20Graph%22%2C%20%20%0A%20%20%20%20%20%20%22scope%22%3A%20%22Files.Read.All%22%20%20%0A%20%20%7D%2C%20%7B%20%20%0A%20%20%20%20%20%20%22resource%22%3A%20%22Microsoft%20Graph%22%2C%20%20%0A%20%20%20%20%20%20%22scope%22%3A%20%22Sites.Read.All%22%20%20%0A%20%20%7D%5D%20%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAccess%20to%20your%20code%20into%20%3CSTRONG%3EBaseClientSideWebPart%3C%2FSTRONG%3E%20area%20and%20ensure%20SharePoint%20Provider%20is%20loaded%20with%20the%20current%20security%26nbsp%3B%20access%20that%26nbsp%3BMgt-File-List%20control%20and%20custom%20graph%20query's%20could%20access%20to%20Microsoft%20Graph%20content.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Eimport%20%7B%20Providers%2C%20SharePointProvider%20%7D%20from%20'%40microsoft%2Fmgt'%3B%0A...%0Aexport%20default%20class%20OneDriveFinderWebPart%20extends%20BaseClientSideWebPart%3CIONEDRIVEFINDERWEBPARTPROPS%3E%20%7B%0A%20%20protected%20onInit()%20%7B%0A%20%20%20%20Providers.globalProvider%20%3D%20new%20SharePointProvider(this.context)%3B%0A%20%20%20%20return%20super.onInit()%3B%0A%20%20%7D%0A...%0A%3C%2FIONEDRIVEFINDERWEBPARTPROPS%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAfter%20defining%20the%20provider%20you%20should%20be%20able%20to%20include%20control%20and%20use%20parameter's%20id%20without%20permissions%20errors.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3Eimport%20%7B%20FileList%20%7D%20from%20'%40microsoft%2Fmgt-react'%3B%0A...%0A%3CFILELIST%20siteid%3D%22%7Bthis._siteID%7D%22%20itemid%3D%22%7Bthis._itemID%7D%22%20itemclick%3D%22%7Bthis.manageFolder%7D%22%3E%3C%2FFILELIST%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--248612546%22%20id%3D%22toc-hId--248612546%22%3EBreadcrumb%20Navigation%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt's%20also%20possible%20to%20use%20Breadcrumb%20to%20include%20the%20path%20of%20folders%20where%20user%20is%20situated%20in%20the%20Library.%3C%2FP%3E%0A%3CP%3EThis%20can%20be%20achieve%20capturing%20the%20%3CSTRONG%3EitemID%3C%2FSTRONG%3E%20of%20Folder%20listed%20in%26nbsp%3B%3CSTRONG%3EMgt-File-List%2C%20%3C%2FSTRONG%3Eusing%20the%20event%20%22%3CSTRONG%3EitemClick%3D%7B(e)%3D%26gt%3B%7B%20console.log(e.details)%3B%7D%3C%2FSTRONG%3E%22.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMore%20information%20can%20be%20found%20on%20Mgt-File-List%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%2Fblob%2Fmain%2Fstories%2Fcomponents%2FfileList.stories.js%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Edocumentation%3C%2FA%3E%20or%20by%20sample%20%22%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fsp-dev-fx-webparts%2Ftree%2Fmaster%2Fsamples%2Freact-onedrive-finder%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ereact-onedrive-finder%3C%2FA%3E%22.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--2056067009%22%20id%3D%22toc-hId--2056067009%22%3EFiltering%20file%20extensions%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%26nbsp%3BMgt-File-List%20property%20%3CSTRONG%3EfileExtensions%3C%2FSTRONG%3E%20allows%20to%20filter%20documents%20by%20file%20extension%2C%20this%20can%20be%20very%20handy%20when%20dealing%20with%20large%20amounts%20of%20documents.%3C%2FP%3E%0A%3CP%3ECode%20below%20shows%20how%20can%20be%20implemented%20a%20multiple%20file%20extensions%20filter.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%20const%20checkFileExtensions%20%3D%20(event%3A%20React.FormEvent%3CHTMLDIVELEMENT%3E%2C%20selectedOption%3A%20IDropdownOption)%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20let%20fileExtensions%3A%20string%5B%5D%20%3D%20%5B%5D%3B%0A%20%20%20%20%20%20if%20(selectedOption.selected%20%3D%3D%20true)%20%7B%0A%20%20%20%20%20%20%20%20fileExtensions.push(selectedOption.key.toString())%3B%0A%20%20%20%20%20%20%20%20fileExtensions%20%3D%20%5B...fileExtensions%2C...this.state.fileExtensions%5D%3B%0A%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20fileExtensions%20%3D%20this.state.fileExtensions.filter(e%20%3D%26gt%3B%20e%20!%3D%3D%20selectedOption.key%20)%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20this.setState(%7B%0A%20%20%20%20%20%20%20%20fileExtensions%3A%20%5B...fileExtensions%5D%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%7D%3B%0A.....%0A%3CDROPDOWN%20placeholder%3D%22Select%22%20label%3D%22Select%20file%20extensions%22%20multiselect%3D%22%22%20options%3D%22%7B%5B%22%3E%3C%2FDROPDOWN%3E%0A...%0A%3CFILELIST%20fileextensions%3D%22%7Bthis._fileExtensions%7D%22%20...%3D%22%22%3E%3C%2FFILELIST%3E%3C%2FHTMLDIVELEMENT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-431445824%22%20id%3D%22toc-hId-431445824%22%3EStyling%20with%20Mgt-File-List%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Mgt-File-List%20includes%20Light%20and%20Dark%20theme%20but%20you%20can%20also%20provide%20your%20custom%20styles.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CFILELIST%20classname%3D%22mgt-dark%22%20...%3D%22%22%3E%3C%2FFILELIST%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ETo%20create%20your%20own%20custom%20style%20look%20and%20feel%20you%20can%20use%20css%20elements%20to%20customize%20Mgt-File-List.%3C%2FP%3E%0A%3CP%3EBelow%20some%20of%20the%20options%20available%20and%20shared%20in%20%3CA%20style%3D%22background-color%3A%20%23ffffff%3B%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%2Fblob%2Fmain%2Fstories%2Fcomponents%2FfileList.stories.js%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EFileList%20Stories%3C%2FA%3E%20of%20the%20Beta%20Version.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-css%22%3E%3CCODE%3E.mgtfilelist%20%7B%0A%20%20--file-list-background-color%3A%20%23eff6fc%3B%0A%20%20--file-item-background-color--hover%3A%20%23deecf9%3B%0A%20%20--file-item-background-color--active%3A%20%23c7e0f4%3B%0A%20%20--file-list-border%3A%200px%20solid%20%23white%3B%0A%20%20--file-list-box-shadow%3A%20none%3B%0A%20%20--file-list-padding%3A%200px%3B%0A%20%20--file-list-margin%3A%200%3B%0A%20%20--file-item-border-radius%3A%200px%3B%0A%20%20--file-item-margin%3A%200px%200px%3B%0A%20%20--file-item-border-top%3A%201px%20solid%20%23dddddd%3B%0A%20%20--file-item-border-left%3A%201px%20solid%20%23dddddd%3B%0A%20%20--file-item-border-right%3A%201px%20solid%20%23dddddd%3B%0A%20%20--file-item-border-bottom%3A%201px%20solid%20%23dddddd%3B%0A%20%20--show-more-button-background-color%3A%20%23fef8dd%3B%0A%20%20--show-more-button-background-color--hover%3A%20%23ffe7c7%3B%0A%20%20--show-more-button-font-size%3A%2014px%3B%0A%20%20--show-more-button-padding%3A%2016px%3B%0A%20%20--show-more-button-border-bottom-right-radius%3A%2012px%3B%0A%20%20--show-more-button-border-bottom-left-radius%3A%2012px%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1376008639%22%20id%3D%22toc-hId--1376008639%22%3ESearch%20in%20Shared%20Libraries%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20control%20by%20the%20property%20%3CSTRONG%3E%22fileListQuery%22%3C%2FSTRONG%3E%20also%20allow%20the%20usage%20Graph%20Drive%20Search%20method%20to%20find%20Items%20in%20the%20Drive.%20Below%20an%20sample%20on%20how%20you%20could%20use%20a%20dynamic%20to%20search%20items%20in%20Drives.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%2F%2FMake%20query%20on%20Shared%20Library%20or%20OneDrive%20Library%20%0Aconst%20checkSearchDrive%20%3D%20(SearchQuery%3A%20string)%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20if%20(this.state.siteID%20!%3D%20%22%22)%20%7B%0A%20%20%20%20%20%20%20%20this.setState(%7B%0A%20%20%20%20%20%20%20%20%20%20searchDrive%3A%20%22%2Fsites%2F%22%20%2B%20this.state.siteID%20%2B%20%22%2Fdrive%2Froot%2Fsearch(q%3D'%22%20%2B%20SearchQuery%20%2B%20%22')%22%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20this.setState(%7B%0A%20%20%20%20%20%20%20%20%20%20searchDrive%3A%20%22%2Fme%2Fdrive%2Froot%2Fsearch(q%3D'%22%20%2B%20SearchQuery%20%2B%20%22')%22%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3B%0A%20%0A%2F%2FSearch%20Box%20for%20Shared%20Library%20%0A%3CSEARCHBOX%20placeholder%3D%22Search%20Drive%22%20onsearch%3D%22%7BcheckSearchDrive%7D%22%20onclear%3D%22%7BcheckClear%7D%22%3E%3C%2FSEARCHBOX%3E%0A%0A%2F%2FDisplay%20search%20content%0A%7B(this.state.searchDrive%20!%3D%20%22%22)%20%26amp%3B%26amp%3B%0A%20%20%20%20%3CFILELIST%20filelistquery%3D%22%7BsearchDrive%7D%22%3E%3C%2FFILELIST%3E%0A%7D%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-416340715%22%20id%3D%22toc-hId-416340715%22%3EFinal%20sample%20solution%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBelow%20the%20final%20result%20of%20the%20configuration%20of%20%3CSTRONG%3EMgt-File-List%3C%2FSTRONG%3E%20react%20controls%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22OneDrivefinderSample3.gif%22%20style%3D%22width%3A%20758px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F278825iCE51537904B9BDD2%2Fimage-dimensions%2F758x465%3Fv%3Dv2%22%20width%3D%22758%22%20height%3D%22465%22%20role%3D%22button%22%20title%3D%22OneDrivefinderSample3.gif%22%20alt%3D%22OneDrivefinderSample3.gif%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ESolution%20can%20be%20found%20in%20the%26nbsp%3B%3CEM%3ESharePoint%20Framework%20Client-Side%20Web%20Part%20Samples%3C%2FEM%3E%26nbsp%3B-%20%3CSTRONG%3EOneDrive%20finder%3C%2FSTRONG%3E%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fsp-dev-fx-webparts%2Ftree%2Fmaster%2Fsamples%2Freact-onedrive-finder%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fpnp%2Fsp-dev-fx-webparts%2Ftree%2Fmaster%2Fsamples%2Freact-onedrive-finder%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EPS%3A%20Solution%20will%20be%20updated%20with%20release%20version%20when%26nbsp%3B%3CSTRONG%3EMgt-File-List%3C%2FSTRONG%3E%20is%20available%20by%20the%26nbsp%3BMicrosoft%20Graph%20Toolkit.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1391113748%22%20id%3D%22toc-hId--1391113748%22%3EHow%20to%20start%20with%20Microsoft%20Graph%20Toolkit%20and%20SharePoint%20Online%3C%2FH3%3E%0A%3CP%3EThere%20is%20a%20very%20good%20articles%20on%20how%20to%20start%20for%20example%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Ftoolkit%2Fget-started%2Fbuild-a-sharepoint-web-part%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EBuild%20a%20SharePoint%20web%20part%20with%20the%20Microsoft%20Graph%20Toolkit%3C%2FA%3E%3C%2FP%3E%0A%3CP%3ETo%20use%20the%20%3CSTRONG%3EMgt-File-List%20control%20in%20Beta%20version%3C%2FSTRONG%3E%20please%20use%20the%20following%20packages.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3Enpm%20i%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F41501%22%20target%3D%22_blank%22%3E%40microsoft%3C%2FA%3E%2Fmgt%40next%0Anpm%20i%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F41501%22%20target%3D%22_blank%22%3E%40microsoft%3C%2FA%3E%2Fmgt-react%40next%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3EPS%3A%20The%20Microsoft%20Graph%20Toolkit%20Team%20made%20available%20access%20to%20Beta%20version%20of%20Mgt-File-List%20and%20react.%20Final%20version%20package%20can%20be%20monitor%20and%20accessible%20in%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Emicrosoft-graph-toolkit.%3C%2FA%3E%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20will%20hope%20this%20article%20could%20help%20you%20onboard%20when%20the%20%3CSTRONG%3EMgt-File-List%3C%2FSTRONG%3E%20control%20becomes%20officially%20available.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESupport%20Documentation%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Ftoolkit%2Fget-started%2Fbuild-a-sharepoint-web-part%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EBuild%20a%20SharePoint%20web%20part%20with%20the%20Microsoft%20Graph%20Toolkit%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fsp-dev-fx-webparts%2Ftree%2Fmaster%2Fsamples%2Freact-onedrive-finder%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EPnP%20SPFX%20Samples%20%22One%20Drive%20finder%22%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20Graph%20Toolkit%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fonedrive-concept-overview%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EOneDrive%20file%20storage%20API%20overview%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fresources%2Fonedrive%3Fview%3Dgraph-rest-1.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EWorking%20with%20files%20in%20Microsoft%20Graph%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fresources%2Fsharepoint%3Fview%3Dgraph-rest-1.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EWorking%20with%20SharePoint%20sites%20in%20Microsoft%20Graph%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fgraph%2Fgraph-explorer%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EGraph%20Explorer%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%2Fblob%2Fmain%2Fspecs%2Fmgt-file-list.md%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EFileList%20specifications%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fmicrosoft-graph-toolkit%2Fblob%2Fmain%2Fstories%2Fcomponents%2FfileList.stories.js%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EFileList%20Stories%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2296730%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20solution%20sample%20use%20SharePoint%20Online%20SPFX%20WebPart%20with%26nbsp%3B%3CSTRONG%3EMgt-File-List%26nbsp%3BBeta%20version%3C%2FSTRONG%3E%20control%20to%20retrieve%20documents%20from%20OneDrive%20or%20Shared%20Libraries%20and%20navigate%20between%20their%20folders%20and%20filter%20files%20in%20a%20simple%20way%20using%20%3CSPAN%3EMicrosoft%20Graph%3C%2FSPAN%3E%20API%20Drive%20and%20Sites.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2296730%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EGetting%20started%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHow%20to%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Graph%20Api%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Graph%20Explorer%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%20Samples%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎May 06 2021 09:55 AM
Updated by: