why inserting folder in google drive twice

六月ゝ 毕业季﹏ 提交于 2019-12-11 09:16:32

问题


In my application with vb.net , i managed to create folder and subfolder , file , but my problem is when i create subfolder ,file (in folder parent) , i found my subfolder in drive and in folder parent (i found it twice and i want it only in folder parent )

here is my code

Public Function subfolder_creation(id_sub As String) As String
    Dim subfolder As New Google.Apis.Drive.v2.Data.File()
    subfolder.Title = VF.Text

    subfolder.MimeType = "application/vnd.google-apps.folder"
    Dim ref = Service.Files.Insert(subfolder)
    MessageBox.Show("sous dossier crée")
    ref.Fields = "id"
    Dim a = ref.Execute()
    MessageBox.Show(" Id Subfolder  " & a.Id)
    Dim reference = New ParentReference()
    reference.Id = id_sub
    Dim insert = Service.Parents.Insert(reference, a.Id).Execute
    MessageBox.Show("Création sous dossier avec succés")
    Dim reference_file = New ParentReference()
    reference_file.Id = a.Id
    UploadFile(reference_file.Id)
    Return (a.Id)

i know the problem is from two insert instruction , but i don't know how i solve it


回答1:


I cant test vb but you should be able to do it all in one request

Dim subfolder As New Google.Apis.Drive.v2.Data.File()
subfolder.Title = VF.Text
subfolder.Parents = parentFolderId
subfolder.MimeType = "application/vnd.google-apps.folder"

Add the parent to the body of the insert of the sub folder. In theory you should be able to patch the sub folder with the parent after the insert but its kind of over kill IMO. Just do it when you insert it.



来源:https://stackoverflow.com/questions/45460135/why-inserting-folder-in-google-drive-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!