Problème de téléchargement d'image sur visual basic

Elkh - 24 oct. 2016 à 12:44
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 - 24 oct. 2016 à 15:34
Bonjour alors voila j'ai un gros problème ....
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim errcode As Long
Dim url As String = ListBox1.SelectedIndex
Dim localFileName As String


localFileName = "J:\image.jpg"

'On appelle la fonction api de téléchargement
errcode = URLDownloadToFile(0, url, localFileName, 0, 0)

If errcode = 0 Then

'Message de confirmation que l'image a bien été téléchargée
MsgBox("Fichier bien reçu")
'Comme on a bien reçu l'image on peut la charger

Else

'Sinon on affiche le message d'erreur
MsgBox("Erreur durant le téléchargement")

End If
End Sub

En effet mon but ici c'est de prendre l'url (image) contenu dans l'item de la listbox selectionné pour la télécharger dans "J:\images.jpg" . Sauf que j'ai un problème qui est le suivant :
http://www.casimages.com/i/161024125946218648.png


Avez vous une solution ?

Merci

3 réponses

vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
24 oct. 2016 à 13:36
bonjour
Comment as-tu déclaré l'API URLDownloadToFile ?
0
tu parle de sa ?
 Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long


Si c'est sa oui je l'ai déclaré
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
Modifié par vb95 le 24/10/2016 à 15:08
Oui c'est ça
En VB 6 les paramètres sont des Long sur 32 bits
En VB Net il faut mettre des Integer car les Long sont sur 64 bits


Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Integer, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Integer, _
ByVal lpfnCB As Integer) As Integer
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
24 oct. 2016 à 15:34
Bonjour,

Comme ceci avec une PictureBox:

Option Strict On
Public Class Form1
  Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
 "URLDownloadToFileA" (ByVal pCaller As Integer, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Integer, _
ByVal lpfnCB As Integer) As Integer
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ' Download the file.
        URLDownloadToFile(0, _
            "http://www.planwallpaper.com/static/images/desktop-year-of-the-tiger-images-wallpaper.jpg", _
            "C:\Users\LePivert\Documents\monimage.jpg", 0, 0)'adapter chemin
        ' Display the image.
        PictureBox1.Image = Image.FromFile("C:\Users\LePivert\Documents\monimage.jpg")'adapter chemin
        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
    End Sub
End Class


d'après cela:

http://www.vb-helper.com/howto_download_url_to_file.html

voilà
0
Rejoignez-nous