Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Work in Visual Studio 2008 I have to intrigant Google Drive Backup in My Project
how to do

What I have tried:

I don't have Any Code for vb.net 3.5
Posted
Updated 29-Dec-20 3:47am
Comments
Richard MacCutchan 29-Dec-20 9:00am    
You need to ask Google, it is their product.

1 solution

Start from here and make use of: .NET Quickstart  |  Google Drive API  |  Google Developers[^]

VB.NET based, a version of working copy of code from here[^]:
VB
Imports System.Threading
Imports System.Threading.Tasks

Imports Google
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Drive.v2
Imports Google.Apis.Drive.v2.Data
Imports Google.Apis.Services

Imports Google.Apis.Auth
Imports Google.Apis.Download

 'Dev Console:
 'https://console.developers.google.com/

 'Nuget command:
 'Install-Package Google.Apis.Drive.v2

Private Service As DriveService = New DriveService

Private Sub CreateService()
If Not BeGreen Then
    Dim ClientId = "your client ID"
    Dim ClientSecret = "your client secret"
    Dim MyUserCredential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With {.ClientId = ClientId, .ClientSecret = ClientSecret}, {DriveService.Scope.Drive}, "user", CancellationToken.None).Result
    Service = New DriveService(New BaseClientService.Initializer() With {.HttpClientInitializer = MyUserCredential, .ApplicationName = "Google Drive VB Dot Net"})
End If
End Sub


Private Sub UploadFile(FilePath As String)
Me.Cursor = Cursors.WaitCursor
If Service.ApplicationName <> "Google Drive VB Dot Net" Then CreateService()

Dim TheFile As New File()
TheFile.Title = "My document"
TheFile.Description = "A test document"
TheFile.MimeType = "text/plain"

Dim ByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath)
Dim Stream As New System.IO.MemoryStream(ByteArray)

Dim UploadRequest As FilesResource.InsertMediaUpload = Service.Files.Insert(TheFile, Stream, TheFile.MimeType)

Me.Cursor = Cursors.Default
MsgBox("Upload Finished")
End Sub

Private Sub DownloadFile(url As String, DownloadDir As String)
Me.Cursor = Cursors.WaitCursor
If Service.ApplicationName <> "Google Drive VB Dot Net" Then CreateService()

Dim Downloader = New MediaDownloader(Service)
Downloader.ChunkSize = 256 * 1024 '256 KB

' figure out the right file type base on UploadFileName extension
Dim Filename = DownloadDir & "NewDoc.txt"
Using FileStream = New System.IO.FileStream(Filename, System.IO.FileMode.Create, System.IO.FileAccess.Write)
    Dim Progress = Downloader.DownloadAsync(url, FileStream)
    Threading.Thread.Sleep(1000)
    Do While Progress.Status = TaskStatus.Running
    Loop
    If Progress.Status = TaskStatus.RanToCompletion Then
        MsgBox("Downloaded!")
    Else
        MsgBox("Not Downloaded :(")
    End If
End Using
Me.Cursor = Cursors.Default
End Sub
 
Share this answer
 
Comments
Member 15033065 30-Dec-20 5:14am    
Dev Console For Framework 4.5 or later
I am Using FW 3.5 Pls Provide For 3.5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900