2015-06-09 179 views
0

我正在嘗試與Google Drive API一起使用vb.net。 我看過很多帖子,但我無法理解如何選擇正確的文件夾來添加文件。Google Drive API VB.NET父文件夾的文件夾

我有很多「備份」文件夾,但我現在假設,我想將一個文件添加到「MyApp1」文件夾下的「備份」文件夾中。

我這樣做,但我不知道如何繼續。我搜索我的所有「備份」文件夾,我需要檢查哪一個位於父文件夾「Myapp」下。

Public Shared Function TheRightFolder() As Boolean 

    Try 
     Dim FolderName As String = "Backup" 
     Dim ParentName As String = "MyAPP1" 
     Dim result As Boolean = False 

     Dim request = Service.Files.List() 
     Dim requeststring As String = ("mimeType='application/vnd.google-apps.folder' And trashed=false and title='" & FolderName & "'") 
     request.Q = requeststring 
     Dim Parent = request.Execute() 

     For Each item As File In Parent.Items 
      'Get PARENT NAME OF THE FOLDER TO CHECK IF I AM INSERT IN MY FILE IN THE RIGHT DIRECTORY (USING 'item.Parents DATA'?) 
      '... 
      If ParentName = new_func_to_get_parent_folder_name Then 
       Return True 
      End If 
     Next 
    Catch EX As Exception 
     MsgBox("ERROR" & EX.Message) 
    End Try 
    Return False 

End Function 

我在做什麼錯?

我是否需要改變方式去思考以獲得正確的文件夾?

在此先感謝!

回答

0

實測溶液:

Public Shared Sub ParentsInFolder(ByVal folderId As String) 

    Dim request As ParentsResource.ListRequest = Service.Parents.List(folderId) 
    Try 
     Dim parents As ParentList = request.Execute() 
     For Each parent As ParentReference In parents.Items 
      Dim FileId As String = parent.Id.ToString 
      InfoFromID(Service, FileId) 
     Next 
    Catch e As Exception 
     MsgBox("Errore: " & e.Message) 
    End Try 

End Sub 

和:

Public Shared Sub InfoFromID(ByVal Service As DriveService, fileId As String) 
    Try 
     Dim file As File = service.Files.Get(fileId).Execute 

     Dim Title As String = file.Title 
     Dim MimeType As String = file.MimeType.ToString 
     Dim description As String = file.Description 

    Catch e As Exception 
     MsgBox("Errore: " + e.Message) 
    End Try 
End Sub 
相關問題