Share via

Creating a Dedicated OneDrive Folder For My Web App

Rio Lukman Tawekal 0 Reputation points
2024-07-29T06:28:00.6233333+00:00

I am building a formal mailing web application for my internal company. Is it possible to create a dedicated folder in my OneDrive to upload created Word documents, which can be shared with specified users in my organization for editing or viewing through the Microsoft Graph API?

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | OneDrive | For business | Windows
Microsoft 365 and Office | Word | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hitesh Pachipulusu - MSFT 3,640 Reputation points Microsoft External Staff
    2024-07-29T08:40:37.73+00:00

    Hello @Rio Lukman Tawekal ,

    Thank you for contacting Microsoft Support!

    Yes, you can create a dedicated folder in your OneDrive and share it with specified users using the Microsoft Graph API. Here’s a high-level overview of how you can achieve this:

    1. Create a Folder: You can create a new folder in OneDrive using the Microsoft Graph API. Here’s an example of how to do this with a POST request: POST /me/drive/root/children Content-Type: application/json { "name": "New Folder", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" } This request will create a new folder named “New Folder” in the root directory of your OneDrive. https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online.
    2. Upload Word Documents: Once the folder is created, you can upload Word documents to this folder. You can use a PUT request to upload a file: PUT /me/drive/items/{parent-item-id}:/{filename}:/content Content-Type: application/octet-stream {file-content} Replace {parent-item-id} with the ID of the folder you created and {filename} with the name of the file you are uploading. https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online
    3. Share the Folder: To share the folder with specified users, you can use the sharing API. Here’s an example of how to create a sharing link: POST /me/drive/items/{item-id}/createLink Content-Type: application/json { "type": "edit", // or "view" "scope": "organization" } This will create a sharing link that you can send to users within your organization. https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online
    4. Assign Permissions: You can also assign specific permissions to users: POST /me/drive/items/{item-id}/permissions Content-Type: application/json { "roles": ["write"], // or "read" "grantee": { "user": { "email": "user@example.com" } } } Replace {item-id} with the ID of the folder and "user@example.com" with the email of the user you want to share the folder with.

    These steps should help you set up a dedicated folder in OneDrive, upload Word documents, and share them with specified users for editing or viewing.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.