Jump to content
Xtreme .Net Talk

Download a mp3 file using a axWebBrowser Automatically...


Recommended Posts

Posted
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?
  • *Experts*
Posted

Easiest way, two lines of code:

WebClient client = new WebClient();
client.DownloadFile("http://www.test.com/file.mp3", "c:\\test\\file.mp3");

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted (edited)

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

 

here is the vb code though:

 

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"

Edited by decrypt
Posted

nvm, i have figured out how to do this:

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...