Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi everyone.

I hope you can help me. I dont know how to put this code in two VB net buttons (Get & Download), this code its a sample for google drive api to "Get" and "Download" my files from my google drive account, the documentation its not toot clear for me because im new in apis world.

Imports Google.Apis.Authentication
Imports Google.Apis.Drive.v1
Imports Google.Apis.Drive.v1.Data

Imports System.Net
' ...

Public Class [MyClass]

	' ...

	''' <summary>
	''' Print a file's metadata.
	''' </summary>
	''' <param name="service">Drive API service instance.</param>
	''' <param name="fileId">ID of the file to print metadata for.</param>
	Public Shared Sub printFile(service As DriveService, fileId As [String])
			Dim file As File = service.Files.[Get](fileId).Execute()

			Console.WriteLine("Title: " + file.Title)
			Console.WriteLine("Description: " + file.Description)
			Console.WriteLine("MIME type: " + file.MimeType)
		Catch e As Exception
			Console.WriteLine("An error occurred: " + e.Message)
		End Try
	End Sub

	''' <summary>
	''' Download a file and return a string with its content.
	''' </summary>
	''' <param name="authenticator">
	''' Authenticator responsible for creating authorized web requests.
	''' </param>
	''' <param name="file">Drive File instance.</param>
	''' <returns>File's content if successful, null otherwise.</returns>
	Public Shared Function DownloadFile(authenticator As IAuthenticator, file As File) As System.IO.Stream
		If Not [String].IsNullOrEmpty(file.DownloadUrl) Then
				Dim request As HttpWebRequest = authenticator.CreateHttpWebRequest("GET", New Uri(file.DownloadUrl))
				Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
				If response.StatusCode = HttpStatusCode.OK Then
					Return response.GetResponseStream()
					Console.WriteLine("An error occurred: " + response.StatusDescription)
					Return Nothing
				End If
			Catch e As Exception
				Console.WriteLine("An error occurred: " + e.Message)
				Return Nothing
			End Try
			' The file doesn't have any content stored on Drive.
			Return Nothing
		End If
	End Function


End Class
Sergey Alexandrovich Kryukov 4-Aug-14 17:50pm    
The problem is not clear. Where have you stuck? The code sample is given to you not to copy it and mangle to the one doing something different; first of all, it's given to you for better understanding of documentation. If you start writing code by yourself, you will get what you need.
hitman133 5-Aug-14 14:14pm    
Thanks Sergey, that is a answer i need. In that case, is there any example to use google drive apis in visual basic (not c#) somewhere? (Besides and stackoverflow). I mean something like a quickstar code?
Sergey Alexandrovich Kryukov 5-Aug-14 15:47pm    
First of all, if you need to get good help on .NET, you have to learn to read at least some of C#. Better answers, more answers are usually in C#, but whatever reasons. This is not difficult. Besides, you can always auto-translate from C# to VB.NET with good quality.
hitman133 6-Aug-14 10:01am    
I can learn C# but sadly i must work on a project 95% done in VB. I found a code to Upload files (in VB) to my google drive account and works perfectly, do you think i can modify it a little to make it Download or Get info of my files?
Here is the code:

Thank you.

1 solution

Please see my comments to the question. Perhaps you found less then you could because you did not search for right terms. It's called "Google Drive SDK". You will find plenty of samples, for example:[^].

You really need to understand at least some C#, if you want good .NET help; you cannot count on so much help with VB.NET along, because better developers mostly prefer C#, which is, unlike VB.NET is 1) standardized; 2) is a Microsoft flagship, so Microsoft people take it more seriously and implement innovation first in C#.

To auto-translate between the two, please see my past answers:
Code Interpretation, C# to VB.NET[^],
Need to convert vb code to c#[^].

Share this answer

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