Using ASP.NET C# to Read Data from Google Sheets

In the following tutorial, we’ll be reading a Google Sheet (https://docs.google.com/spreadsheets/d/1-6XeX59-zgqi_z5Bm8dqYyO1z37tfi8Ur7o5mxmmVKo/edit?usp=sharing), porting it into an ASP.NET web site.

  1. Create a new Visual Studio ASP.NET C# project (Ctrl + Shift + N)
  2. Create a new empty web site
  3. Create a new master page, naming it site.master, and a new content page, default.aspx
  4. Visit https://developers.google.com/sheets/api/quickstart/dotnet and enable the Google Sheets API
  5. Go to https://console.developers.google.com/projectcreate, give your project a name, note your project id, and click Next.
  6. Now go to your project: https://console.developers.google.com/apis/library?project=projectid
  7. Enable the Google Sheets API
  8. Visit https://console.developers.google.com/apis/api/sheets.googleapis.com/credentials?project=projectid and click Configure Consent Screen
  9. Click External and click Next
  10. Give you app a name, home page, authorized domain, and add yourself as a test user
  11. Click Add or Remove Scopes
  12. Check the box for See, edit, create, and delete your spreadsheets in Google Drive and View your Google Spreadsheets
  13. Click Save and Continue
  14. Click Go Back to Dashboard
  15. Click Credentials and click Create OAuth client ID
  16. Click Web Application, add a name, and add your authorized JavaScript origins and redirect URIs, including http://localhost/authorize/ and http://127.0.0.1/authorize/
  17. Copy your client id
  18. Copy your client secret
  19. Download your OAuth 2.0 Client Id json file
  20. Save the file credentials.json to your working directory.
  21. Open the NuGet Package Manager Console, and run the following command:
    Install-Package Google.Apis.Sheets.v4
  22. Add a new ASP.NET folder  –> App_Code to your solution
  23. Create a new class in the solution named GoogleSheets.cs