Download a mp3 file using a axWebBrowser Automatically...

decrypt

Junior Contributor
Joined
Oct 6, 2003
Messages
216
I have a program that uses an AxWebBrowser, and gets all the ".mp3" links from the page. The only problem is that i'm stuck at the downloading part. The page gets updated regularly, and it only downloads the files you havn't download (it saves the address downloaded in a .txt file). I have figured out how to do everything except one thing, and that is how to download a .mp3 file and save it to a certain folder. How would i be able to do this using vb.net?
 
Easiest way, two lines of code:
C#:
WebClient client = new WebClient();
client.DownloadFile("http://www.test.com/file.mp3", "c:\\test\\file.mp3");

-ner
 
nice, thanks for the help :) (scroll down)

here is the vb code though:

Visual Basic:
Dim client As New System.Net.WebClient
        client.DownloadFile("http://www.test.com/file.mp3", "c:\test\file.mp3")


edit: i just found a problem.... the files are on an ftp and it says it doesn't support an ftp prefix... how can i fix this? (the program gets the .mp3 links off a webpage, but then the files are on an ftp... how can i get them off there? the error message was "The URI prefix is not recognized"
 
Last edited:
nvm, i have figured out how to do this:

Visual Basic:
Option Strict Off
Option Explicit On 

Imports System.Runtime.InteropServices

Module FTPDownload
    Dim frm1 As Form1
    Private Declare Function InternetCloseHandle Lib "wininet.dll" _
        (ByVal hInternet As IntPtr) As Boolean

    Private Declare Auto Function InternetOpen Lib "wininet.dll" _
        (ByVal lpszAgent As String, _
         ByVal lAccessType As Integer, _
         ByVal lpszProxyName As String, _
         ByVal lpszProxyBypass As String, _
         ByVal dwFlags As Integer) As IntPtr

    Private Declare Auto Function InternetConnect Lib "wininet.dll" _
        (ByVal hInternet As IntPtr, _
         ByVal lpszServerName As String, _
         ByVal nServerPort As Short, _
         ByVal lpszUserName As String, _
         ByVal lpszPassword As String, _
         ByVal dwService As Integer, _
         ByVal dwFlags As Integer, _
         ByVal dwContext As Integer) As IntPtr

    Private Declare Auto Function FtpGetFile Lib "wininet.dll" _
        (ByVal hConnect As IntPtr, _
         ByVal lpszRemoteFile As String, _
         ByVal lpszNewFile As String, _
         ByVal fFailIfExists As Boolean, _
         ByVal dwFlagsAndAttributes As Integer, _
         ByVal dwFlags As Integer, _
         ByVal dwConext As Integer) As Boolean

    Private Declare Auto Function FtpPutFile Lib "wininet.dll" _
        (ByVal hConnect As IntPtr, _
         ByVal lpszLocalFile As String, _
         ByVal lpszNewRemoteFile As String, _
         ByVal dwFlags As Integer, _
         ByVal dwContext As Integer) As Boolean
    Dim currentnumber As Integer
    Sub Main()

        currentnumber = currentnumber + 1
        Dim hInet As IntPtr
        Dim hConn As IntPtr

        hInet = InternetOpen("my ftp", 1, vbNullString, vbNullString, 0)
        Console.WriteLine("hInet = {0}", hInet)

        hConn = InternetConnect(hInet, "no.prefix.com", 21, "", _
 "", 1, 0, 0)
        Console.WriteLine("hConn = {0}", hConn)

        Console.WriteLine("FtpGetFile Result = {0}", FtpGetFile(hConn, _
"folder/in/ftp.txt", "location\ftp.txt", True, 1, 1, 0))

        InternetCloseHandle(hConn)
        InternetCloseHandle(hInet)
    End Sub
 
Back
Top