I have been trying to leverage the Microsoft Graph Api to communicate with user's one drive business inside a MVC web app, have set up everything with delegated permissions and can read and write data in logged-in user's ODB fine however is there any way by which nested folder or directory structure can be created?
Currently I am using code below to create the folder in the root of user's ODB and works fine but looking for a way to create hierarchy of the folders when path is provided before uploading the file in it.
DriveItem rootDirectory = graphServiceClient.Me.Drive.Root.Children.Request().AddAsync(new DriveItem
{
Name = "RootDirectory",
Folder = new Folder(),
}).Result;
And for another folder inside RootDirectory trying this but does not seem to work (where rootDirectory is object created above)
DriveItem subDirectory = graphServiceClient.Me.Drive.Root.Children.Request().AddAsync(new DriveItem
{
Name = "SubDirectory",
Folder = rootDirectory.Folder
}).Result;
Even if it works with some fix, not sure if it is most optimal way to do it, suggestions will be appreciated.