Results 1 to 9 of 9

Thread: [RESOLVED] Downloading File from Google Drive URL

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    27

    Resolved [RESOLVED] Downloading File from Google Drive URL

    Hi guys,

    I've been looking for a way to download a google drive file using via its url. The code snippet below is what I used to download from a dropbox url and it works flawlessly.

    Try
    Dim wc As New WebClient
    AddHandler wc.DownloadFileCompleted, AddressOf wc_DownloadCompleted
    AddHandler wc.DownloadProgressChanged, AddressOf wc_ProgressChanged
    Dim savefile As New SaveFileDialog
    Dim fileurl As String = "https://www.dropbox.com/s/8pd5ovtjh70lylc/CMH%20Infosys.exe?dl=1"
    Dim filelocation As String = InfosysPath & "Infosys\Updates\Infosys.exe"
    If System.IO.File.Exists(filelocation) Then My.Computer.FileSystem.DeleteFile(filelocation)
    wc.DownloadFileAsync(New Uri(fileurl), filelocation)
    Catch ex As Exception
    MsgBox("Download Failed")
    Call LoadData()
    End Try


    I thought maybe if I plug in my google drive url then it should work but it doesn't. I've been looking for a solution online but no luck. Is there a different method of getting this done? I appreciate any help on this topic.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Downloading File from Google Drive URL

    Quote Originally Posted by iantiu View Post
    I thought maybe if I plug in my google drive url then it should work but it doesn't.
    "It doesn't work" is never an adequate explanation. Why actually DOES happen when you use that code? If you need to simplify things for testing, just call DownloadFile without all the other stuff and if it throws an exception, give us all the relevant information about that exception.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Downloading File from Google Drive URL

    By the way, if you're going to post code snippets then please use appropriate formatting tags for readability:
    Code:
            Try
                Dim wc As New WebClient
                AddHandler wc.DownloadFileCompleted, AddressOf wc_DownloadCompleted
                AddHandler wc.DownloadProgressChanged, AddressOf wc_ProgressChanged
                Dim savefile As New SaveFileDialog
                Dim fileurl As String = "https://www.dropbox.com/s/8pd5ovtjh70lylc/CMH%20Infosys.exe?dl=1"
                Dim filelocation As String = InfosysPath & "Infosys\Updates\Infosys.exe"
                If System.IO.File.Exists(filelocation) Then My.Computer.FileSystem.DeleteFile(filelocation)
                wc.DownloadFileAsync(New Uri(fileurl), filelocation)
            Catch ex As Exception
                MsgBox("Download Failed")
                Call LoadData()
            End Try

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Downloading File from Google Drive URL

    Also, if an exception is thrown during the download then the exception handler you have shown there isn't going to catch it, because it is thrown on a secondary thread. You would need to examine the 'e.Error' property in the DownloadFileCompleted event handler for that. There's no indication of whether you're doing that or not in what you've posted.

  5. #5
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Downloading File from Google Drive URL

    Quote Originally Posted by iantiu View Post
    Hi guys,
    I've been looking for a way to download a google drive file using via its url.
    You didn't show us the URL you're using, if it is the one that you get from Google Drive's "Get sharable link" then it won't work because it's not a direct link.

    The sharable link would look like this:
    https://drive.google.com/open?id=xxxxxxxx

    To get the direct link, use this link:
    https://docs.google.com/uc?export=download&id=xxxxxxxx

    Replace the Xs with your file id

    Hope that helps

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    27

    Re: Downloading File from Google Drive URL

    Quote Originally Posted by jmcilhinney View Post
    "It doesn't work" is never an adequate explanation. Why actually DOES happen when you use that code? If you need to simplify things for testing, just call DownloadFile without all the other stuff and if it throws an exception, give us all the relevant information about that exception.
    First of all, I appreciate your input. Sorry about the vagueness. What I run the code with a google drive url, the file appears to download but when I run the file, the file is "corrupt" No exception is thrown.

    I am new to google drive and I've been using dropbox a while now. I never realized there are two different urls for google drive. Apparently, I've been using the open url. This one that cPubis suggested worked for me:

    https://drive.google.com/uc?export=d...HLsOaH-QUZ-vag

    I know the solution will be quite simple, I just can't figure out what I did wrong. Thank you for your responses jmcilhinney and cPubis. Have a great day!

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Downloading File from Google Drive URL

    Quote Originally Posted by iantiu View Post
    This one that cPubis suggested worked for me:
    Excellent. Be sure to use the Thread Tools menu to mark this thread Resolved.

  8. #8
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Downloading File from Google Drive URL

    Quote Originally Posted by iantiu View Post
    I never realized there are two different urls for google drive.
    It's not your fault. The direct link trick is not documented on any of Google's websites. It's kind of a hack, a workaround, it's leaching and Google will hate it if you use it intensively. Be wise using it or else Google will block it for all of us. Have a nice day.

  9. #9
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Downloading File from Google Drive URL

    Sorry double post

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width