This blog post demonstrates how to build with Radzen an Angular app that will access Microsoft OneDrive using Microsoft Graph API and Azure Active Directory authentication!
Creating the app and MSGraph data-source
Create a new Radzen application, add MSGraph data-source similar to our article and add Files.Read
scopes/permissions.
Creating a page with Tree and DataGrid to browse OneDrive files and folders
- Create new page named OneDrive, drag and drop a Row and two Column component from Radzen toolbox. Set 3 and 9 for the size of first and second column.
- Call MSGraph data-source
getDrives()
method on page Load event and define two page propertiesgetDrivesResult
for the returned data anddrive
for the first drive in the collection. - After
getDrives()
call invoke MSGraph data-sourcegetDrivesRoot()
method with${drive.id}
as parameter and define page propertyrootId
to${result.id}
. - Drag and drop Tree component from Radzen toolbox to the first column, bind it to
getDrivesResult
page property and define two levels usingmicrosoft.graph.drive
andmicrosoft.graph.driveItem
schemas. Setowner.user.displayName
for the first level Text property andname
for the second level Text property. - Call MSGraph data-source
getDrivesItemsChildren()
method on Tree component NodeExpand event with three parameters:- id =
${drive.id}
. - driveItemId =
${event.level == 0 ? this.rootId : event.data.id}
. ProviderootId
or current node/itemid
depending onlevel
. - $filter =
file eq null
. Filter drive items to return only folders. Execute${event.children = result.value}
aftergetDrivesItemsChildren()
method call.
- id =
- Add new event handler to the Tree component NodeLoaded event and execute
${event.leaf = event.data.folder ? event.data.folder.childCount == 0 : false}
. The tree node will not be expandable if there are no children. - Add new event handler to the Tree component NodeSelect event, define
selectedFolderId
page property with value${event.level == 0 ? this.rootId : event.data.id}
, invokegetDrivesItemsChildren()
method with two parameters:- id =
${drive.id}
. - driveItemId =
${event.level == 0 ? this.rootId : event.data.id}
. and set page propertyselectedItemChildren
to${result.value}
.
- id =
- Drag and drop DataGrid component from Radzen toolbox to the second column, bind it to
selectedItemChildren
and define desired columns. CheckAllowSorting
andAllowFiltering
. - Run the application, login using your Microsoft credentials and browse your OneDrive files and folders.
Enjoy!