Welcome to ADO.NET Access 2003—your ultimate hub for VB.NET and ADO.NET programming excellence. Discover in-depth tutorials, practical code samples, and expert troubleshooting guides covering a broad range of topics—from building robust WinForms applications and seamless MS Access integration to working with SQL Server, MySQL, and advanced tools like WebView2 and Crystal Reports. Whether you're a beginner or a seasoned developer, our step-by-step articles are designed to empower you to optimize.

Looking for MS Access Developer❓❓

Application developer

Post Page Advertisement [Top]

How to Upload Files to OneDrive from WinForms C# .NET 9.0 using Microsoft Graph SDK

OneDrive Cloud Upload in C# WinForms 2025

In the previous 'fifth' post➡️DropBox File Upload, we looked at sharing files to DropBox App Folder using DropBox Api.

In this tutorial, we’ll walk through how our GSMArena scraper built with WinForms C# .NET 9.0 can upload files directly to OneDrive using the Microsoft Graph SDK. This integration is useful for cloud backups, file sharing, and ensuring scraped data is accessible from anywhere.

In this sixth installment of our GSMArena Scraper series, we’ll cover how to prepare your OneDrive account for file uploads and walk through the C# techniques we used to integrate OneDrive file upload functionality into our WinForms application using the Microsoft Graph SDK. We’ll also break down our custom OneDriveUploader.cs class to understand how it works under the hood.

1. Preparing Your OneDrive Account

Before you can upload files to OneDrive, you must set up an application in the Azure Portal to get the credentials for Microsoft Graph API.

  1. Sign in to your Microsoft account and go to App Registrations.
  2. Click New Registration.
  3. Enter an Application Name (e.g., GSMArenaUploaderApp).
  4. Set the supported account type (e.g., "Accounts in this organizational directory only").
  5. Redirect URI can be left blank for now or set to https://login.microsoftonline.com/common/oauth2/nativeclient for testing.
  6. Click Register.
Azure portal register new app vs2022

After registration, note down:
  • Application (client) ID
  • Directory (tenant) ID

Next, create a Client Secret:

  1. Go to Certificates & secrets.
  2. Click New client secret, add a description, set expiry, and click Add.
  3. Copy the secret value immediately — you’ll need it in your WinForms app.

2. Installing and Using Microsoft Graph SDK

To upload to OneDrive, we’ll use the Microsoft Graph .NET SDK, which simplifies calling OneDrive APIs.

Install Microsoft Graph SDK

Open your project in Visual Studio 2022 and install the package via NuGet:

Install-Package Microsoft.Graph
Install-Package Microsoft.Identity.Client

Authentication

Use the following code snippet to authenticate and create a GraphServiceClient instance:

using Microsoft.Graph;
using Microsoft.Identity.Client;

var clientId = "YOUR_CLIENT_ID";
var tenantId = "YOUR_TENANT_ID";
var clientSecret = "YOUR_CLIENT_SECRET";

var confidentialClient = ConfidentialClientApplicationBuilder.Create(clientId)
    .WithClientSecret(clientSecret)
    .WithTenantId(tenantId)
    .Build();

var authProvider = new ClientCredentialProvider(confidentialClient);

var graphClient = new GraphServiceClient(authProvider);

Uploading a File to OneDrive

Once authenticated, uploading is straightforward:

using (var fileStream = System.IO.File.OpenRead(@"C:\path\to\yourfile.txt"))
{
    await graphClient.Me.Drive.Root.ItemWithPath("UploadedFile.txt")
        .Content
        .Request()
        .PutAsync<DriveItem>(fileStream);
}

This code uploads yourfile.txt to the root of the authenticated OneDrive account.

OneDrive file upload functionality in GSMArena scraper WinForms C# vs2022


3. Integrating with GSMArena Scraper

In our GSMArena WinForms scraper, after the scraping process finishes, we automatically generate an export file (CSV or JSON). This file is then passed to the OneDrive upload method above, ensuring that every scrape session is backed up to the cloud.

Example Integration

private async Task UploadScrapedDataToOneDrive(string filePath)
{
    using (var fileStream = System.IO.File.OpenRead(filePath))
    {
        await graphClient.Me.Drive.Root.ItemWithPath(System.IO.Path.GetFileName(filePath))
            .Content
            .Request()
            .PutAsync<DriveItem>(fileStream);
    }
}

Conclusion

By integrating Microsoft Graph SDK into your WinForms C# .NET 9.0 project, you can seamlessly upload files to OneDrive. This is especially valuable for projects like our GSMArena scraper, where data backup and cloud accessibility are crucial.

With this setup, every run of the scraper can automatically store its output on OneDrive, eliminating manual uploads and ensuring data is always safe and accessible.

📦 GSMArena Mobile Brands

GitHub Repository Showcase

This repository contains structured data for GSM Arena mobile brands, ideal for apps and web scrapers. Clean, JSON-formatted brand lists ready to use in your projects.

⭐ View on GitHub

💬 Have questions about this project? Want to see the next part of the tutorial? Drop a comment below! And don't forget to check out my other .NET and WinForms guides.

 Here are some online Visual Basic lessons and courses:

😱 Web Data Scraping Service - Part3 user agents rotation 🧩 Web Data Scraping Service - GSMArena Part5 Csharp Cloud upload DropBox WinForms 🧩 Web Data Scraping Service - GSMArena Part4 Csharp Proxies rotation 🧩 Web Data Scraping Service - GSMArena Part3 Csharp Async programming 🧩 Web Data Scraping Service - GSMArena Part2 Csharp user-agents 🗝️ Web Data Scraping Service - GSMArena Part1 Csharp ©️ C# VS. Visual Basic 🔟 Top 10 Programming Terms 📘 Desktop application Development - VB.NET WebView2 🌐 Desktop application Development - Internet connectivity 📩 Desktop application Development - POP3 mail Server 🎲 Desktop application Development - VB.NET Strings 🔊 Desktop application Development - VB.NET Sound and Music 📊 Desktop application Development - VB.NET ProgressBar Control 🚫 Desktop application Development - TroubleShooting 💾 Microsoft Access Developer - VB.NET Best Practice Guide 🔁 Desktop application Development - VB.NET DataReader 📺 Desktop application development - Controls BackColor Texture 📚 Database Developer - SyBase Advantage 🌄 Desktop application Development - Images ⌨️ Desktop application Development - VB.NET KeyPress vs KeyDown 💻 Desktop App Developer - Install SSL on Windows 🔬 Programming - Object Oriented Programming OOP 💬 Desktop App Developer - Text Files 🎁 Desktop App Developer - VB.NET DeopBox API 🚗 Desktop App Developer - VB.NET Google Drive API 👨‍💻 Desktop WinForms Development - VB.NET Compare two TreeViews

No comments:

Bottom Ad [Post Page]