Ejemplo para descargar archivos de internet con Visual Basic 2005 0
Hoy os voy a poner un ejemplo para poder descargar archivos con visual basic 2005.
Los controles que vamos a necesitar son los siguientes:
- Un control Button
- Un control textbox llamado “txt_Url”
– Un control textbox llamado “txt_path_destino”

Una vez dicho esto, vamos con el codigo en cuestion:
1. Function Descargar_Archivo(ByVal Url As String, _
2. ByVal Path_Destino As String) As Boolean
3. If Url = vbNullString Or Path_Destino = vbNullString Then
4. MsgBox(”No se indicó la url o el archivo de destino”, _
5. MsgBoxStyle.Critical, “Error”)
6. Else
7. If Len(Dir(Path_Destino)) <> 0 Then
8. MsgBox(”el archivo destino ya existe. Por favor,escoja otro destino diferente”, _
9. MsgBoxStyle.Exclamation, “Error”)
10. Else
11. On Error Resume Next
12. My.Computer.Network.DownloadFile(Url, Path_Destino)
13. If Err.Number = 0 Then
14. Descargar_Archivo = True
15. Else
16. MsgBox(Err.Description)
17. End If
18. Err.Clear()
19. End If
20. End If
21. End Function
22.
23. Private Sub Form1_Load(ByVal sender As System.Object, _
24. ByVal e As System.EventArgs) _
25. Handles MyBase.Load
26. Button1.Text = “Download” ‘lo podemos llamar al boton como queramos.
27. End Sub
28.
29. Private Sub Button1_Click(ByVal sender As System.Object, _
30. ByVal e As System.EventArgs) Handles Button1.Click
31. Dim ret As Boolean
32. ret = Descargar_Archivo(txt_url.Text, txt_path_destino.Text)
33.
34. If ret Then
35. MsgBox(”El archivo se ha descargado correctamente”, MsgBoxStyle.Information)
36. End If
37.
38. End Sub









subscribe to comments RSS
Este post no no tiene aun comentarios