Shortening URLs Using TinyUrl API in .net

Here is a quick method to shorten URLs using the TinyUrl API in .net – C# and VB


public static string MakeTinyUrl(string Url)
if (Url.Length <= 30)
return Url;
if (!Url.ToLower().StartsWith("http") && !Url.ToLower().StartsWith("ftp"))
Url = "http://" + Url;
var request = WebRequest.Create("" + Url);
var res = request.GetResponse();
string text;
using (var reader = new StreamReader(res.GetResponseStream()))
text = reader.ReadToEnd();
return text;
catch (Exception)
return Url;


Public Shared Function MakeTinyUrl(ByVal Url As String) As String
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 request As var = WebRequest.Create("" + Url)
Dim res As var = request.GetResponse()
Dim text As String
Using reader As var = New StreamReader(res.GetResponseStream())
text = reader.ReadToEnd()
End Using
Return text
Catch Exception ex
Return Url
End Try
End Function

0 thoughts on “Shortening URLs Using TinyUrl API in .net

  1. Pingback: Hosting and Software + Services : Converting url to tinyURL in C#

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s