none
Mit Google API Einen Unterordner in GoogleDrive erstellen und in diesem eine Datei kopieren. RRS feed

  • Question

  • Hallo Zusammen,
    ich möchte gerne eine Datei in einen Ordner bzw. Unterordner in GoogleDrive kopieren.
    Ich programmiere in VB 2019.
    Ich habe sehr viele Seiten besucht jedoch wird überall nur das kopieren in das GoogleDrive Root geschrieben.
    Weder in einen Ordner geschweige denn in einem Unterordner.

    Was ich bissher geschaft habe:
    Ordner in GoogleDribe erstellen
    Unterordner in GoogleDrive erstellen
    Datei ins Root von GoogleDrive kopieren.

    Mein bisheriger Code:

        Private Sub UploadFile_create(FilePath As String)
    
            ' Checking if the Service is still alive, if not create the service again.
            If moService2.ApplicationName <> "GoogleCloud-Backup" Then CreateService()
    
            Dim findrootid = New Google.Apis.Drive.v3.Data.File() With {
            .Name = "Testordner",
            .MimeType = "application/vnd.google-apps.folder"
        }
            Dim findrequest As Google.Apis.Drive.v3.FilesResource.ListRequest = moService3.Files.List
    
            Dim list1 As Google.Apis.Drive.v3.Data.FileList = findrequest.Execute()
    
    
            Dim FolderID = Nothing
    
            For Each item As Google.Apis.Drive.v3.Data.File In list1.Files
                If item.MimeType = "application/vnd.google-apps.folder" Then
                    If item.Name = "Testordner" Then
                        FolderID = item.Id
                        Exit For
                    End If
                End If
            Next
    
            Dim oGDriveFile As New Google.Apis.Drive.v3.Data.File With {
            .OriginalFilename = System.IO.Path.GetFileName(FilePath),
            .Name = .OriginalFilename,
            .Description = "Google Drive Backup",
            .MimeType = GetMimeType(FilePath)}
            oGDriveFile.Id = New List(Of ParentReference)() From {New ParentReference() With {.Id = FolderID}}.ToString
    
            Dim bArrByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath) ' Your File Path from where you would want to upload from.
            Dim oStream As New System.IO.MemoryStream(bArrByteArray)
    
            Dim oUploadRequest_create As Google.Apis.Drive.v3.FilesResource.CreateMediaUpload
            oUploadRequest_create = moService3.Files.Create(oGDriveFile, oStream, oGDriveFile.MimeType)
            oUploadRequest_create.Fields = FolderID
            oUploadRequest_create.Alt = Google.Apis.Drive.v3.FilesResource.CreateMediaUpload.AltEnum.Json
            oUploadRequest_create.Upload()
    
            MsgBox("Create abgeschlossen!")
        End Sub


    • Edited by Gneufzen Thursday, December 5, 2019 12:43 PM
    Thursday, December 5, 2019 12:42 PM

Answers