Search code examples
c#asp.net.nettinyurl

Using tinyurl.com in a .Net application ... possible?


I found the following code to create a tinyurl‍.com URL:

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

This will automatically create a tinyurl URL. Is there a way to do this using code, specifically C# in ASP.NET?


Solution

  • You should probably add some error checking, etc, but this is probably the easiest way to do it:

    System.Uri address = new System.Uri("http://tinyurl.com/api-create.php?url=" + YOUR ADDRESS GOES HERE);
    System.Net.WebClient client = new System.Net.WebClient();
    string tinyUrl = client.DownloadString(address);
    Console.WriteLine(tinyUrl);