Visual Basic Grab an image from online
By: a guest | Apr 12th, 2010 | Syntax:
VB.NET | Size: 1.00 KB | Hits: 137 | Expires: Never
Imports System.Text
Imports System.Web
Imports System.IO
Imports System.Net
Module Module1
Sub Main(ByVal sArgs() As String)
If sArgs.Length = 0 Then 'If there are no arguments
Console.WriteLine("You need to specify a url")
Else 'We have some arguments
Dim url As String
Dim client As WebClient = New WebClient()
url = sArgs(0)
Dim uri As Uri = New Uri(url)
Dim sFilename As String
Dim iLast As Integer = uri.Segments.GetUpperBound(0)
Try
sFilename = uri.Segments(iLast)
client.DownloadFile(uri, sFilename)
'if error occurs then application doesnt crash
Catch ex0 As WebException
Console.WriteLine(ex0.Message)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End If
Console.ReadLine()
End Sub
End Module