.NET URL Shorten-er Library

I’ve been working on a few applications were I’ve been using TinyURL a lot. So, I thought I’d create a library for .NET that contains functions for the most popular URL Shorten-er sites.

 

Function TinyURL
Function TimesURL
Function DoiopURL
Function MemURL
Function DwarfURL
Function SnipURL
Function ShorlURL
Function LoajURL
Function BitlyURL
Function IsGdURL
Function SixURL
Function TightURL
Function UrlXURL
Function YepItURL

Total there are 14 function that all server the same purpose. It’s really a personal preference as to what service you want to use. Each function accepts 1 overload and returns a single String.

Example: 


dim sTest As String = TimesURL(sURL)

The library will be available soon. Any interest in this or ideas please leave a comment.

Popularity: unranked [?]

TimesURL & .NET

I’ve got a few emails regarding http://timesurl.at. If you want to use this service you can still the use code from [TinyURL & .NET]. All you have to do is change one line of code.

Change

http://tinyurl.com/api-create.php?url=

to

http://timesurl.at/api/rest.php?url=

And there you have it. This also works with most other URL shortener sites. If not, just email me and I”ll write up some code for the site you need.

Popularity: unranked [?]

TinyURL & .NET

Ever want to parse a TinyURL in your .NET application? TinyURL has a very simple and easy to use API. I’ll guide you through the process of returning a TinyURL in VB.NET 2008 and C# .NET 2008

First off you want to create a function that returns a string.
Simple enough, this function ask for the parameter of URL and will return a string. 

Public Function GetTinyUrl(ByVal URL As String) As String
End Function

Next you want to make sure you’re not using the TinyURL service for no reason. The API is designed for links over 30 characters long. So if you have a 20 character URL TinyURL will end up giving you a 20-35 character URL. So let’s check this first. We’re going to use the Try/Catch method incase something might go wrong. If so, we’ll return the users URL back to him.

Try
    If Url.Length <= 30 Then
       Return URL
     End If
Catch
       Return Url
     End Try

Next we are going to check our link to make sure it starts with “http”.

If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
  Url = "http://" + Url
End If

Now that we have that done, lets declare some variables. “req” is used to create  our request to use the API, “rsp” is used to get the response from our request. Simple enough, right? “txt” is used to store our ending result from our Stream Reader.

Dim req As WebRequest = WebRequest.Create("http://tinyurl.com/api-create.php?url=" + Url)
Dim rsp As WebResponse = req.GetResponse()
Dim txt As String

Now lets actually read our request and store the result in our txt variable. Also, let’s go ahead and Return our result to the user.

Using rdr As StreamReader = New StreamReader(rsp.GetResponseStream())
          txt = rdr.ReadToEnd()
End Using
Return txt

Now, let’s put it all together and we have this. Pass the URL parameter and recieve the TinyURL in return.

    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

I hope this helps you out, and don’t forget to comment!

Popularity: unranked [?]

ScreenTweet

I found a lot of tweets on Twitter where folks are wanting an easy, fast and free way to take a screenshot and post it on Twitter. Well here it is folks!
ScreenTweet
ScreenTweet will allow you to take a screenshot of your desktop or an open window. It allows you to use your choice of host services and URL shortner services. This is just a teaser, but expect the download link to appear real soon!

Popularity: unranked [?]