microsoft / hack-together

Hack Together: Microsoft Graph and .NET is a hackathon for .NET developers to learn Microsoft Graph and Microsoft 365.
MIT License
523 stars 85 forks source link

Project: Sharepoint System.IO Abstraction deamon #72

Open OzBob opened 1 year ago

OzBob commented 1 year ago

Project name

msgraph-sharepoint-filesystem-deamon

Description

On the 'dev' branch

This is a deamon app sample that will connect to the MSGraph using the dotnet sdk, it will allow an authorised application to manage a file system drive in sharepoint, with the following methods on the interface IFileSystem:

Repo URL

https://github.com/OzBob/hack-together/tree/ozbob/dev

Team members

OzBob

waldekmastykarz commented 1 year ago

Awesome! Thank you for your hack!

waldekmastykarz commented 1 year ago

Hey @OzBob, would you mind recording a short video walkthrough of your hack? Any format will work. It's not required for the hackathon but it would help us showcase your work both internally at Microsoft and publicly in the community. 😊

OzBob commented 1 year ago

first attempt at OBS screen capture 2nd vid with a working example of listing sites, despite the MSGraph explorer not listing sites. it will also include a debug view of the site\drives endpoint call: https://github.com/OzBob/hack-together/blob/ozbob/dev/src/SharepointFileSystem/0Console/Experiments/SharepointExamples.cs#L41 and the drive{id} endpoint blank result.https://github.com/OzBob/hack-together/blob/ozbob/dev/src/SharepointFileSystem/0Console/Experiments/SharepointExamples.cs#L55 2023-03-15 20-39-17ScreenCapture.zip

OzBob commented 1 year ago

@waldekmastykarz OBS screen capture uploading

OzBob commented 1 year ago

@waldekmastykarz / community can I please ask for some help on how to query msgraph 'sites' using dotnet client when query is: ...sites/{siteid}/drives/{driveid}/root:/BaseDocuments as per @PaoloPia' example here https://youtu.be/rjZnuuKQu3c?t=247

waldekmastykarz commented 1 year ago

@OzBob, could you please elaborate a bit what you'd like to achieve? In your question you're referring to sites but then sharing the API URL to a document library.

OzBob commented 1 year ago

Thanks @waldekmastykarz! Much appreciated.

My project is to 'Copy a local folder up to Sharepoint'. Starting with a single file C:\BaseDocuments\folder\subfolder\file.docx Check Sharepoint to see if it exists. Upload it or update it into Sharepoint at: clientsite\basedrive\BaseDocuments\folder\subfolder\file.docx

I used Paolos on Youtube to guide me how to get the Graph Explorer REST endpoints working, but I am still not getting the msgraph dotnet client to work.

I have used the MSGraph Client to

  1. get the site.Id, from Sites["tenant.sharepoint.com:/sites/clientsite/"]
  2. get the Drive[0].Id from Sites[siteid].Drives -> match on name 'basedrive' to get 'driveid'

My sticking point now is to find the children under the sites\drives\root\

  1. MsGraph Explorer at returns children here ...sites/{siteid}/drives/{sdriveid}/root:/BaseDocuments How do I write that in C#?

I'm using this to get the Children 'folder'

 var rootWithChildren = await graphClient
                                 .Drives[drive.Id]
                                 .Root
                                 .GetAsync(requestConfiguration => {
                                    requestConfiguration.QueryParameters.Expand = new string[] { "children" };
                                 });
var firstRootWithChildrenId = rootWithChildren[0].Id
var BaseFolder = await graphClient
           .Drives[siteDriveid]
           .Items[firstRootWithChildrenId]
           .GetAsync();

Once I get to the child document 'file.docx' I'll start researching bulk upload/download as some docs will be bigger than 4MB

waldekmastykarz commented 1 year ago

Have you seen this https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=csharp#list-children-in-the-root-of-the-current-users-drive?