从谷歌硬盘下载文件

时间:2016-03-19 17:43:56

标签: vb.net google-drive-api

首先,对不起我的英语。其次,我想创建一个应用程序,在每次启动时从谷歌驱动器下载.txt文件,文件被定义(我的意思是,它在驱动器中)。它只是一个文件,但是,当我启动应用程序时,文件被下载,但是它不包含任何内容。 这是我的代码:

Private Function ReadLine(ByVal Line As Integer, ByVal lista As List(Of String)) As String
    Return lista(Line - 1)
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If My.Computer.Network.IsAvailable() = True Then
        Try
            My.Computer.FileSystem.DeleteFile("C:\WINDOWS\" & fisier)
        Catch ex As Exception
        End Try

        My.Computer.Network.DownloadFile("https://doc-14-7c-docs.googleusercontent.com/docs/securesc/17t22h2a63tpkhdgv047v6i0s5a9o8bm/qgqjocmi87jt0up72gfpg9dseeo3pt84/1458396000000/07699472972018131827/07699472972018131827/0B8iVIf__yN1FUDV1STNWODJUYms?e=download&nonce=5jnki0mtgo520&user=07699472972018131827&hash=0gi5r6k7rm2uob14062tlbsk0nhpkoo1", _
                                         "C:\WINDOWS\" & fisier)
        Dim reader As New IO.StreamReader("C:\WINDOWS\" & fisier)
        Dim lista As New List(Of String)
        While Not reader.EndOfStream
            lista.Add(reader.ReadLine)
        End While
        reader.Close()
        If My.Computer.FileSystem.FileExists(fisier2) = False Then
            lblWould.Text = ReadLine(1, lista)
        Else
            Dim nr As Integer
            nr = Val(My.Computer.FileSystem.ReadAllText(fisier2))
            nrx = nr
        End If
        Dim contain As String = My.Computer.FileSystem.ReadAllText("C:\WINDOWS\" & fisier)
        contain = contain.Replace(lblWould.Text, "SEEN!")
        My.Computer.FileSystem.WriteAllText("C:\WINDOWS\" & fisier, contain, False)
    Else
        MsgBox("Trebuie sa fi connectat la internet!")
        Me.Close()
    End If
End Sub
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click, btnNo.Click
    Dim reader As New IO.StreamReader("C:\WINDOWS\" & fisier)
    Dim lista As New List(Of String)
    Dim a As String
    While Not reader.EndOfStream
        a = reader.ReadLine()
        If Not a = "SEEN!" Then
            lista.Add(reader.ReadLine)
        End If
    End While
    lblWould.Text = lista(nrx + 1)
    nrx += 1
    Dim contain As String = My.Computer.FileSystem.ReadAllText("C:\WINDOWS\" & fisier)
    contain = contain.Replace(lblWould.Text, "SEEN!")
    My.Computer.FileSystem.WriteAllText("C:\WINDOWS\" & fisier, contain, False)
End Sub`

谢谢!

0 个答案:

没有答案