Search code examples
c#.netasp.net-coremicrosoft-graph-apionedrive

Subscribe to a folder with MS graph SDK


How can I make it work with the Microsoft Graph SDK (.Net and C#) that I can only subscribe to one folder ? (I want to code a webhook based on this).

public async Task<ActionResult<string>> Get() {
      var graphServiceClient = GetGraphClient();
      var sub = new Microsoft.Graph.Subscription();
      
      sub.ChangeType = "updated";
      sub.NotificationUrl = config.Ngrok + "/api/notifications";

      sub.Resource = "/drives/{driveID}/root/";
      sub.ExpirationDateTime = DateTime.UtcNow.AddMinutes(5);
      sub.ClientState = "SecretClientState";

      var newSubscription = await graphServiceClient.Subscriptions.Request().AddAsync(sub);

So far I can only subscribe to everything in the root but not to a specific folder in Onedrive.


Solution

  • Yes, On personal OneDrive you could subscribe to the root folder or any subfolder within that drive but in OneDrive for business, you could only subscribe to root folder. Let me know if you required further assistance on this.

    Note: You cannot subscribe to drive or driveItem instances that are not folders, such as individual files. You could refer to our official document here.

    So you can create folder within the root, in that case you could allow your user to create folder where they can upload their files.

    Hope it would helps