upload file to one drive
How to upload file to one drive from dot net core 10 web app
2 answers
-
Danny Nguyen (WICLOUD CORPORATION) 7,185 Reputation points • Microsoft External Staff • Moderator
Hi @hirenkumar patel ,
Yes, you can use Microsoft Graph for this scenario.
For uploading files to OneDrive from an ASP.NET Core web app, the Microsoft Graph upload session approach is relevant, especially if the file may be large. The Graph SDK creates an upload session and uploads the file in smaller slices instead of sending the whole file in one request.
You can refer to this Microsoft Learn article here: Upload large files using the Microsoft Graph SDKs
The C# sample in that article shows the main flow:
- Open the file stream.
- Create an upload session for the target OneDrive path.
- Use
LargeFileUploadTask<DriveItem>to upload the file. - Optionally track progress and handle errors.
Please also make sure your app authentication and Microsoft Graph permissions are configured correctly for the OneDrive account you want to upload to. For example, if uploading to the signed-in user’s OneDrive, you would usually work with
/me/drive; if uploading to another user or shared drive, the Graph path and permissions may be different. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback.Thank you.
-
Danny Nguyen (WICLOUD CORPORATION) 7,185 Reputation points • Microsoft External Staff • Moderator
Hi, just checking in. Did my answer help with your problem? Feel free to reach out if you need any help.
If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback.
Thank you.
-
Danny Nguyen (WICLOUD CORPORATION) 7,185 Reputation points • Microsoft External Staff • Moderator
As we haven’t heard back from you for a while, we’ll go ahead and close this thread for now.
If you still need assistance later, feel free to reach out.
Thank you for your understanding.
Sign in to comment -
AI answer
Use Microsoft Graph from the ASP.NET Core app to upload the file into the user’s OneDrive.
High-level steps:
- Register an app in Microsoft Entra ID
- Create a Microsoft 365 developer tenant.
- Register an app in Microsoft Entra ID with delegated permissions for Files (for example, Files.ReadWrite or Files.ReadWrite.All).
- Configure redirect URI and client secret as described in the Microsoft Graph ASP.NET Core tutorial.
- Configure the ASP.NET Core app to call Microsoft Graph
- Add Microsoft Authentication and Microsoft Graph client configuration (client ID, tenant ID, client secret, scopes) as in the module “Download and upload files in an ASP.NET Core app with Microsoft Graph”.
- Implement authentication so the user signs in with their Microsoft 365 account and the app obtains an access token for Microsoft Graph.
- Build a file upload UI in the Razor Page or MVC View
- Add an HTML form with
<input type="file" name="file" />andenctype="multipart/form-data". - Post the file to a controller or page handler that receives it as
IFormFile.
- Add an HTML form with
- Use Microsoft Graph to upload the file to OneDrive
- After the user signs in, use the authenticated Graph client to upload the file stream to the user’s OneDrive.
- The Learn module “Download and upload files in an ASP.NET Core app with Microsoft Graph” covers:
- Listing files in the user’s OneDrive.
- Downloading files.
- Uploading user files from the browser into OneDrive.
- For large files, use the Graph SDK large file upload task
- Many Microsoft Graph entities support resumable uploads.
- Instead of sending the whole file in one request, create an upload session and upload the file in slices using the Microsoft Graph SDK “large file upload task”.
- This is recommended for large files to avoid timeouts and to support resume.
By following the ASP.NET Core + Microsoft Graph training module, the app can authenticate users, accept a file from the browser, and upload it into the signed-in user’s OneDrive, using regular or large-file upload depending on file size.
References:
AI-generated content may be incorrect. Read our transparency notes for more information. - Register an app in Microsoft Entra ID
