Skype Profile Image Downloader in Visual Basic

Introduction: In this tutorial we are going to be making a simple program in Visual Basic to download someones Skype profile picture. How It Works: We are going to use the Skype API to act as a link to get the profile picture, from that we can use a simple download function within Visual Basic .NET to download the returned image through the link. Design: This program will take two components; Button, named 'skypeButton', text set as 'Download Profile Image' Textbox, named 'skypeText', where the user will enter the skype profile username. Verifying: Once the button has been clicked, we first want to check that the text falls within the Skype username requirements (greater than 5 characters but less than 33) and only contains letters/numbers. First we check the character length...
  1. Private Sub skypeButton_Click(sender As Object, e As EventArgs) Handles skypeButton.Click
  2. Dim username As String = skypeText.Text
  3. Dim runDownload As Boolean = True
  4. If (username.Length >= 6 And username.Length <= 32) Then
  5. 'Next code goes in here.
  6. Else : MsgBox("Username is not the right length!")
  7. End If
  8. End Sub
Then we iterate through each character and ensure that it is allowed (contained within our allowed characters list), if any of them is not there, we set the boolean value of our earlier defined 'runDownload' variable to false...
  1. Dim allowed As Char() = "abcdefghijklmnopqrstuvwxyz0123456789"
  2. username = username.ToLower() 'Easier to check against the allowed characters, case insensitive.
  3. For Each character As String In username
  4. Dim isFound As Boolean = False
  5. For Each c As Char In allowed
  6. If c = character Then isFound = True
  7. Next
  8. If Not (isFound) Then
  9. MsgBox(character)
  10. runDownload = False
  11. End If
  12. Next
Then if the 'runDownload' variable is True/y/yes/ok/1 then no error occured, the username is ok, and we try to download the image...
  1. If (runDownload) Then
  2. Dim link As String = "http://api.skype.com/users/" + username + "/profile/avatar"
  3. Dim fs As New SaveFileDialog
  4. fs.Filter = "JPEG Files | .jpg | PNG Files | *.png"
  5. fs.FilterIndex = 1
  6. fs.ShowDialog()
  7. If (My.Computer.FileSystem.FileExists(fs.FileName)) Then
  8. Dim result As MsgBoxResult = MsgBox("File already exists, overwrite it?", MsgBoxStyle.YesNo, "File Exists")
  9. If (result = MsgBoxResult.Yes) Then
  10. Dim wc As New WebClient
  11. wc.DownloadFile(link, fs.FileName)
  12. End If
  13. Else
  14. Dim wc As New WebClient
  15. wc.DownloadFile(link, fs.FileName)
  16. End If
  17. Else : MsgBox("Not all the characters meet the Skype requirements for a username. Please try again with a different username")
  18. End If
We let the user choose a save location, file name and file type out of .jpg or .png.

Add new comment