0

DriveItems only seem to be accessible by ID if you know which drive it resides in.

What's the best way to globally identify a DriveItem? e.g a URN that can be used with the C# graph SDK?

Preferably one way that will work with Sharepoint, Teams and OneDrive for business

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Jan Martin
  • 408
  • 3
  • 11
  • 1
    for graph api, [drive item](https://learn.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0&tabs=http#http-request) can only be reached by path or id – Tiny Wang Nov 02 '22 at 05:55

1 Answers1

0

If you know the URL of the drive item, you can encode the URL and use shares endpoint.

Encoding URL:

var stringData = "https://tenant.sharepoint.com/sites/{site_name}/{path_to_file}";
var byteData = stringData.getBytes();
var base64String = Base64.getEncoder().encodeToString(byteData);

var sharedDriveItem = await graphClient.Shares[$"{base64String}"]
    .DriveItem
    .Request()
    .GetAsync();

Not sure if it's useful in your case.

Resources:

Accessing drivItems

user2250152
  • 14,658
  • 4
  • 33
  • 57
  • Thanks I had seen this but wasn't sure if it was appropriate - do you know if using sharing links is reliable? e.g. do they expire? I see it requires ReadWrite permission so I guess it changes the document - perhaps this will not be appropriate for my needs. – Jan Martin Nov 03 '22 at 09:09
  • @JanMartin I think that created links do not expire unless a default expiration policy is enforced for the organization. When creating sharing links you can specify expirationDateTime. https://learn.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=http#request-body – user2250152 Nov 03 '22 at 09:36