BEvilM
BEvilM

Reputation: 53

Failing to getting Drive items and Drive Folders from Sharepoint Graph in C# and Graph Explorer

I'm having some problems with the Graph Drive items. I'm trying to access a file with a certain structure to read, write and update files in a folder. Thing is that I can't access the lead folder map, I've tried different possibilities in C# and Graph Explorer.


The folder structure ► MySite.sharepoint.com ► MyUnderSite ► MainDriveFlder ► CustomerDriveFolder ► Driveitems

and

MySite ► MyUnderSite ► MainDriveFlder ► DriveItems

MySite = Sites/CustomerSitename.sharepoint.com:
MyUnderSite = Sites/CustomerSitename.sharepoint.com:/sites/CustomerSitename2:
MainDriveFlder = Customer_Files
CustomerDriveFolder = CustomerNr1_Files
Driveitems = word.docs or pic.png or exel.xlsx


What i tried

In C#

graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives.Request().GetAsync();
graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives[""].Request().GetAsync();

https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children

graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives["Customer_Files"].Root.Children.Request().GetAsync();

https://graph.microsoft.com/v1.0/sites/{tenant}.sharepoint.com:{path-to-site(ie: /sites/HR)}:/drives

graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives.Request().GetAsync();

https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{folder-name}/{file-name.txt}:/content

graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives["Customer_Files"].Items["ID"].Request().GetAsync();

https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{folder-name}:/children https://graph.microsoft.com/v1.0/me/drive/root/children

Graph Explorer This works i get a response https://graph.microsoft.com/v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives

Then, I get a response with a filename = "name": "Customer_Files", that is a "driveType": "documentLibrary"

But when I go further into this folder or want to call items from it, I can't access them, C# same issue. I've tried all these and no response from errors though no right URL specification.(part what i tried)

GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Testfiledrive
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/customer_files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/'Customer_Files'
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/"Customer_Files"
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/{Customer_Files}
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files Export
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/root
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/root/search(q='Customer_Files')
GET /v1.0/me/drive/root/search(q='Customer_files')
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/special/documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/Shared%20Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Shared%20Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files:/root/children
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files/root/children
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer_files/children
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer_files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_files/items
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_files:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/root
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/b!iDg2xo9-yUSnkkcTcFXBP_aUL9EMu9JIqr1aGCz8KH9m3E7rhgkqRLyqeK93F96_
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/root
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/list
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:
GET /v1.0/me/drive/root/children
GET /v1.0/me/drives/Customer_files

So the main problem is that i cant access or call the files in Customer_Files and in the Customer_Files/Customernr1_Files.

Can someone help me in finding the right structure in c# and graph explorer. To access these files. If i provided the wrong or to less information let me know. I've been searching for weeks.

I cant give all the information and change some code names to protect the costumer.

Upvotes: 0

Views: 1117

Answers (2)

BEvilM
BEvilM

Reputation: 53

Solution

var returnitem = await graphserviceClient.Sites["Site-ID"].Drives["Dive-ID"].Root.Children.Request().GetAsync();//gets all Children in the drive

var returnitemfiles = await graphserviceClient.Sites["Site-ID"].Drives["Drive-ID"].Items["File-ID"].Children.Request().GetAsync();//gets one Child and returns all the Children of that file

var returnitemfile = await graphserviceClient.Sites["Site-ID"].Drives["Dive-ID"].Items["File-ID"].ItemWithPath(fileBase.FileName).Content.Request().PutAsync<DriveItem>(fileBase.InputStream);//upload a file to the drive in a folder by id only usable for small files under 4 MB

Site-ID can look somthing like this = "c6669213-7e4f-44c9-a792-65737055c13f"

Dive-ID ="b!iDh2xo8-yUSnkkcTcFXBP_aUL5EMu9JIqr1aGCz2KH9m3E7rhgkqRLyqiK93Z96_"

Folder-ID = "01BPZAU2WZBX5ZT55GHTCYVV3WZERIWJM6"

FileBase i used HttpPostedFileBase

Upvotes: 1

Allen Wu
Allen Wu

Reputation: 16438

Based on your structure, I can't tell whether your "MyUnderSite" is a subsite of "MySite" or another site collection.

I will analyze both cases.

"MyUnderSite" is a site collection:

  1. Call GET https://graph.microsoft.com/v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite to get the id of "MyUnderSite".
  2. Call GET https://graph.microsoft.com/v1.0/sites/{id of "MyUnderSite"}/drive/root:/customer_files.

"MyUnderSite" is a subsite:

  1. Call GET https://graph.microsoft.com/v1.0/sites/MySite.sharepoint.com/sites to list the subsites and find the id of "MyUnderSite".

  2. Call GET https://graph.microsoft.com/v1.0/sites/{id of "MyUnderSite"}/drive/root:/customer_files.

Upvotes: 1

Related Questions