Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Actually , i develop an application in vb.net .
The first step , i want to create a folder and subfolder in google drive (of course i need a test if a folder exist or not ) , then , i want to upload a file in specific folder in google driver

here is my code

VB
Public Sub createfolder()

    Dim dossier = New Google.Apis.Drive.v2.Data.File()

    dossier.Title = dat_sauv.SelectedItem 'title from combobox in forms
    dossier.MimeType = "application/vnd.google-apps.folder"

    Dim rep = Service.Files.Insert(dossier)
    rep.Fields = "id"

    Dim file = rep.Execute()

    'sub folder Creation
    Dim subfolder = New Google.Apis.Drive.v2.Data.File()

    'title from radio button in forms
    If (VT.Checked = True) Then
        subfolder.Title = VT.Text
    ElseIf (vm.Checked = True) Then
        subfolder.Title = VM.Text
    ElseIf (VI.Checked = True) Then
        subfolder.Title = VI.Text
    Else
        subfolder.Title = VF.Text
    End If

    subfolder.MimeType = "application/vnd.google-apps.folder"

    Dim res = Service.Files.Insert(subfolder)
    res.Fields = "id"

    Dim fil = res.Execute()
    dossier.Parents = subfolder

end sub


What I have tried:

i managed to create the folder , but not the subfolder
and i managed to upload a file in google drive but not in specific folder
Posted
Updated 24-Jul-17 2:43am
v3

1 solution

It does not look like you are passing the Parent folder id to the Subfolder before executing the create folder command...
 
Share this answer
 
Comments
Member 8587273 24-Jul-17 9:05am    
1 / how and where i do it ?
i called a method createfolder() in button event

2/ for upload file to an specific folder , here is my code

Private Sub UploadFile(FilePath As String)


' la partie de l'import du fichier dans le drive
Dim ByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath) ' lire le fichier dans un tableau d'octet
Dim Stream As New System.IO.MemoryStream(ByteArray) ' lire le bloc d'octet du tableau et écrit les données dans une mémoire temp

' Insertion fichier dans le drive
Dim f As New Google.Apis.Drive.v2.Data.File()
f.Title = fichier_txt.Text
f.Description = " fichier drive"
f.MimeType = "text/plain , image/jpeg"

Dim Up As FilesResource.InsertMediaUpload = Service.Files.Insert(f, Stream, f.MimeType)
Up.Upload() ' la méthode qui fait l'upload dans le drive

MsgBox("Upload Successful ") 'Succés d'upload

End Sub
Graeme_Grant 24-Jul-17 9:13am    
I created my own API lib for Google Drive API. Looking at the documentation, you set it in the metadata... Work with Folders  |  Drive REST API  |  Google Developers[^] - Look at the "Inserting a file in a folder" example... folder works the same...

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