logo
search
OneDrive File Issues

How to Upload Files to OneDrive Using .NET Web API

Aamir Naveed AkramAamir Naveed Akram Oct 12, 2026 869 views

Question details

Learn how to programmatically upload files to OneDrive using a .NET Web API application.

How to Upload Files to OneDrive Using .NET Web API
Product
OneDrive
Device & OS
not provided
Scenario
Developing a .NET application that requires creating folders and uploading files to a user's or organizational OneDrive using the Microsoft Graph API.
Observed behavior
Requires the correct implementation of the Microsoft Graph API, Azure app registration, and handling of client credentials to successfully upload items.
Before you start

Ensure you have an active Microsoft Azure account and have registered an Azure Active Directory (Azure AD) application with the necessary Microsoft Graph permissions.

Solution 1Recommended

Use Microsoft Graph API for OneDrive Uploads

The standard and most reliable method to upload files to OneDrive in a .NET application is using the Microsoft Graph REST API.

Microsoft provides two main methods for uploading files to OneDrive via the Graph API: Simple Upload and Resumable Upload. Simple uploads are ideal for small files (under 4MB), while resumable upload sessions are required for larger files to handle network interruptions efficiently.

1
Register Application in Azure

Log in to the Azure Portal, navigate to Azure Active Directory, and register a new application to obtain your Client ID, Tenant ID, and generate a Client Secret.

2
Configure API Permissions

Under your app's 'API permissions', add Microsoft Graph permissions such as 'Files.ReadWrite' or 'Files.ReadWrite.All' and grant admin consent if required by your organization.

3
Implement Simple Upload (Under 4MB)

In your .NET code, use an HTTP PUT request targeting the endpoint '/me/drive/items/{parent-id}:/{filename}:/content' with the file stream passed in the request body.

4
Implement Resumable Upload (Over 4MB)

First, create an upload session by sending a POST request to '/createUploadSession'. Use the returned upload URL to send the file bytes in chunks using HTTP PUT requests until the entire file is transferred.

Use Microsoft Graph API for OneDrive Uploads
Official API Documentation: For detailed C# code examples, SDK usage, and advanced error handling, refer to the official Microsoft Graph OneDrive upload documentation.
Free Microsoft Office alternative

Explore WPS Office for Seamless Document Management

While integrating OneDrive APIs for your applications, you might also need a robust suite to handle the actual documents. WPS Office is a free, lightweight, and powerful alternative to Microsoft Office that perfectly handles all standard office document formats with zero learning curve.

  1. 1. Download and Install: Visit the official WPS Office website and download the free installer for your operating system.
  2. 2. Open Your Documents: Launch WPS Office and open any Word, Excel, or PowerPoint files instantly thanks to its high format compatibility.
  3. 3. Edit and Sync: Edit your documents and save them locally or directly sync them to your preferred cloud storage platforms.
Fully compatible with Microsoft Office formats (.docx, .xlsx, .pptx)Lightweight application that uses minimal system resourcesBuilt-in cloud features to easily manage your uploaded files across devicesFamiliar user interface for seamless migration from other office suites
microsoft office alternative - wps office

Frequently Asked Questions

What is the maximum file size for a simple upload to OneDrive via the Graph API?

Simple API uploads are strictly restricted to files that are 4MB or smaller. If your .NET application needs to upload files larger than 4MB, you must implement a resumable upload session.

Why am I getting an 'Access Denied' error when uploading via .NET Web API?

This error typically occurs if your Azure App Registration lacks the correct API permissions (like Files.ReadWrite) or if the authentication token you are passing in your API request has expired or lacks admin consent.

Can I upload files directly to a specific folder in OneDrive?

Yes, you can upload files directly into a targeted folder by specifying the folder path in the API endpoint URL. You can use the syntax '/drive/root:/{folder-path}/{filename}:/content' when making your PUT request.