Click here to Skip to main content
16,020,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am compiling a program in VB.NET which downloads a past-paper (for example) from www.xyz.com but it seems that I cannot download from the link which appears to be like this: " http://xyz.com/index.php/directory/download?location=A%20Level/Biology/Edexcel/2001%20Jun/2001%20June%20Module%202B.pdf " but when I try to download from a direct link such as " http://www.somewebsite.com/files/afile.file " it works. Here is my code, so please tell me what to correct! Any help is greatly appreciated ( btw I am a beginner in VB.NET, so I need exact answers with explanations please)

VB
Public Class Form1
  Dim downloadsize As Long
  Dim Downloadedsize As Long
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim req As Net.HttpWebRequest
    Dim resp As Net.HttpWebResponse
    req = Net.HttpWebRequest.Create("http://xyz.com/index.php/directory/download?location=A Level/Chemistry/Edexcel/2012 Jan/6CH08_01_msc_20120209.pdf")
    req.AllowAutoRedirect = True
    resp = req.GetResponse
    req.Method = Net.WebRequestMethods.Http.Get
    downloadsize = resp.ContentLength
    ProgressBar1.Maximum = downloadsize
    BackgroundWorker1.RunWorkerAsync()
    Timer1.Start()
End Sub

  Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    My.Computer.Network.DownloadFile("http://xyz.com/index.php/directory/download?location=A Level/Chemistry/Edexcel/2012 Jan/6CH08_01_msc_20120209.pdf", "D:\edexcellogo.pdf", "", "", False, 60000, True)
  End Sub

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Downloadedsize = My.Computer.FileSystem.GetFileInfo("D:\pp.doc").Length
    ProgressBar1.Value = Downloadedsize
  End Sub
End Class
Posted
Updated 9-Jul-14 3:06am
v2
Comments
CHill60 9-Jul-14 9:12am    
See the question mark? Everything after that is the query string that is being passed to the site. Assuming that these things are stored in the "download" folder, try removing "location=" and replace the ? with /. If that doesn't work then that is not where they store their documents - possibly to stop people downloading them like this.
Member 10753250 10-Jul-14 14:31pm    
@CHill60 , thanks for the reply bro but that does not work.
When I use the WebBrowser the file can be downloaded but the user is promted to download the file and I wouldnt like this to happen. Alternatively, is there any way that I can take over the download from WebBrowser?
CHill60 10-Jul-14 19:20pm    
Wouldn't know, but I've removed the abusive/spam answer so you question is back in the queue. By the way, I'm not your "bro" ... be aware of cultural differences :-)
As to the prompt, and not finding the file, if it is not your own website then talk to the admin of that site
Member 10753250 11-Jul-14 4:44am    
Thank You Sir :)
the files are open for download for anyone

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900