Share via

upload file to one drive

hirenkumar patel 0 Reputation points
2026-06-10T03:15:50.18+00:00

How to upload file to one drive from dot net core 10 web app

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Danny Nguyen (WICLOUD CORPORATION) 7,345 Reputation points Microsoft External Staff Moderator
    2026-06-10T06:01:39.3366667+00:00

    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:

    1. Open the file stream.
    2. Create an upload session for the target OneDrive path.
    3. Use LargeFileUploadTask<DriveItem> to upload the file.
    4. 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.

    Was this answer helpful?

    2 people found this answer helpful.

  2. AI answer

    2026-06-10T03:15:59.98+00:00

    Use Microsoft Graph from the ASP.NET Core app to upload the file into the user’s OneDrive.

    High-level steps:

    1. 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.
    2. 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.
    3. Build a file upload UI in the Razor Page or MVC View
      • Add an HTML form with <input type="file" name="file" /> and enctype="multipart/form-data".
      • Post the file to a controller or page handler that receives it as IFormFile.
    4. 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.
    5. 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.

    Was this answer helpful?

    1 person found this answer helpful.

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.