Forum Discussion

jacksor's avatar
jacksor
Copper Contributor
Apr 12, 2021

Set filepath of created folder/file in OneDrive

Hi there, this is INCREDIBLY basic so please forgive my ignorance but:

How can I modify the filepath for a POST request through MS Graph to write a file/folder to OneDrive?

At present the below will write to the root directory of OneDrive:

{
"name": "Foo",
"folder": {}
}

However, how would I make create a folder in a path such as "Documents\Foo"?

I've just been playing around with it in Graph Explorer but can't work it out.

Thanks!

Rich

  • Hi,

    I really don't know if this could be the same or maybe I am completely wrong, but some time ago I needed to do the same with the email inbox. I needed to create a subfolder inside the inbox/root folder. After some digging I found out, I needed the fetch the ID of the root folder first before I could create a subfolder

    A part of the blog ( I still need to publish 😞 )

    ----------------------------------------------------------------------------------------------------
    Most of the script was already published on the internet but I needed it to create a subfolder inside the inbox not in the root of the mailbox. So I changed some parts. Let’s break down what I changed:

    To create a subfolder inside the Inbox folder, you will need to ID of the inbox folder. Otherwise it does not work.

    $Mailboxfolders = Invoke-RestMethod -Uri $Uri -Headers $Header -Method Get -ContentType "application/json"
    $mailboxinboxid = $mailboxfolders.id

    Now we have the inbox ID we can change the URI were the subfolder need to be created

    "https://graph.microsoft.com/v1.0/users/$mailbox/mailFolders/$mailboxinboxid/childfolders

Resources