Share Pastebin
Guest
Private paste!

Visual Basic Grab an image from online

By: a guest | Apr 12th, 2010 | Syntax: VB.NET | Size: 1.00 KB | Hits: 137 | Expires: Never
Copy text to clipboard
  1. Imports System.Text
  2. Imports System.Web
  3. Imports System.IO
  4. Imports System.Net
  5.  
  6. Module Module1
  7.  
  8.     Sub Main(ByVal sArgs() As String)
  9.  
  10.         If sArgs.Length = 0 Then                'If there are no arguments
  11.             Console.WriteLine("You need to specify a url")
  12.         Else                                    'We have some arguments        
  13.             Dim url As String
  14.             Dim client As WebClient = New WebClient()
  15.  
  16.             url = sArgs(0)
  17.  
  18.             Dim uri As Uri = New Uri(url)
  19.             Dim sFilename As String
  20.             Dim iLast As Integer = uri.Segments.GetUpperBound(0)
  21.  
  22.             Try
  23.                 sFilename = uri.Segments(iLast)
  24.                 client.DownloadFile(uri, sFilename)
  25.  
  26.                 'if error occurs then application doesnt crash
  27.             Catch ex0 As WebException
  28.                 Console.WriteLine(ex0.Message)
  29.             Catch ex As Exception
  30.                 Console.WriteLine(ex.Message)
  31.             End Try
  32.  
  33.         End If
  34.  
  35.         Console.ReadLine()
  36.  
  37.     End Sub
  38. End Module