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 Google Drive from WinForms C# .NET 9.0 using Google Cloud Console.

Google Cloud Console Drive API File Upload

In the previous 'sixth' post ➡️ OneDrive File Upload, we looked at sharing files to Microsoft OneDrive App Folder using Microsoft OneDrive Api 'Microsoft Graph SDK'.


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


1. Preparing Google Drive & API Project

To allow our GSMArena Scraper to upload files directly to Google Drive, we first need to prepare an API project in Google Cloud Console.


Google Cloud Console Drive API WinForms


  1. Create or log into your Google Cloud account.
  2. Navigate to APIs & Services → Library and enable Google Drive API.

  3. Go to APIs & Services → Credentials and click Create Credentials → OAuth Client ID.
  4. Configure the OAuth Consent Screen (set application name, user type, and add your test Gmail account).
  5. Download the client_secret.json file – this contains the credentials we’ll use in our C# project.

2. Adding Google Drive .NET SDK

Open your scraper project in Visual Studio 2022 (targeting .NET 9.0). Install the official Google Drive .NET Client library from NuGet:

Install-Package Google.Apis.Drive.v3
Install-Package Google.Apis.Auth

This will give us access to the authentication flow and Drive upload methods.

3. Implementing File Upload

Now we integrate Google Drive upload inside our WinForms scraper. The snippet below shows how to authenticate and upload a file:

using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System.IO;
using System.Threading;

private void UploadToGoogleDrive(string filePath)
{
    string[] Scopes = { DriveService.Scope.DriveFile };
    string ApplicationName = "GSMArena Scraper Uploader";

    UserCredential credential;
    using (var stream =
        new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
    {
        string credPath = "token.json";
        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.FromStream(stream).Secrets,
            Scopes,
            "user",
            CancellationToken.None,
            new FileDataStore(credPath, true)).Result;
    }

    // Create Drive API service.
    var service = new DriveService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = ApplicationName,
    });

    var fileMetadata = new Google.Apis.Drive.v3.Data.File()
    {
        Name = Path.GetFileName(filePath)
    };
    FilesResource.CreateMediaUpload request;
    using (var stream = new FileStream(filePath, FileMode.Open))
    {
        request = service.Files.Create(fileMetadata, stream, "application/octet-stream");
        request.Fields = "id";
        request.Upload();
    }

    var file = request.ResponseBody;
    MessageBox.Show("Uploaded to Google Drive, File ID: " + file.Id);
}

In the code above:

4. Testing the Integration

Build and run the project, then trigger your upload method. If everything is configured correctly, your scraper’s exported data (CSV, Excel, JSON, etc.) will now be saved directly to your Google Drive.

5. GitHub Repository

The full source code is available in our GitHub repository:

📦 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

 Here are some online Visual Basic lessons and courses:

💹 Web Data Scraping Service - GSMArena Part6 Csharp Cloud upload MS OneDrive WinForms 🦺 Web Data Scraping Service - GSMArena Part5 Csharp Cloud upload DropBox WinForms 🟥 Web Data Scraping Service - GSMArena Part4 Csharp Proxies rotation  Web Data Scraping Service - Part3 user agents rotation 🧩 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]