Make your own TinyURL application.

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
1 post Page 1 of 1
Contributors
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

this is a very simple tool you can make that will allow you to short long URLs but using TinyURL.com API.
ok Start up Visual Studio and create a new project.

Controls to add to form1
2 - TextBox Controls
1 - Button Control


Control - Name - Text

TextBox1 - TextBox1 - nothing
TextBox2 - TextBox2 - nothing
Button1 - Button1 - Shorten

You can rename them if you wish.

on Form one double click the form to load the Form1_Load Event()
Code: Select all
Private Sub Form1_Load()
      TextBox1.Text = ""
       TextBox2.Text = ""
End Sub
all this does is resets the .Text()

Double click the Button1 Conttrol so it loads the Button1_Click Event()
Code: Select all
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim url As String = TextBox1.Text
        TextBox2.Text = GetTinyUrl(url)
    End Sub
Now, under the Form1 "End Class" statement
create a New Module, or you can add a Module to your project.
In Module1 paste this code.
Code: Select all
Module modTinyURL
    Public Function GetTinyUrl(ByVal URL As String) As String
        Try
            If Url.Length <= 30 Then
                Return URL
            End If
            If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
                Url = "http://" + Url
            End If
            Dim req As WebRequest = WebRequest.Create("http://tinyurl.com/api-create.php?url=" + Url)
            Dim rsp As WebResponse = req.GetResponse()
            Dim txt As String
            Using rdr As StreamReader = New StreamReader(rsp.GetResponseStream())
                txt = rdr.ReadToEnd()
            End Using
            Return txt
        Catch
            Return Url
        End Try
    End Function
End Module
ok, so remeber the Button1_Click Event()
Code: Select all
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim url As String = TextBox1.Text
        TextBox2.Text = GetTinyUrl(url)
    End Sub
when you paste a long URL into TextBox1 and then click the Button1 Control.
It will send the long URL you just pasted in TextBox1 to the TinyURL API for processing.
When the API has completed its task, it will return the new shortened URL and the new value will
be displayed in the TextBox2 Control.

So now all you have to do is copy the new shortened URL from TextBox2 and paste it in your borwser
or wherever you need a shortened URL.
Image
1 post Page 1 of 1
Return to “Tutorials”