<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FailBoy &#187; TinyUrl</title>
	<atom:link href="http://www.failboy.net/tag/tinyurl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.failboy.net</link>
	<description>We reserve the right FAIL</description>
	<lastBuildDate>Tue, 03 Aug 2010 20:45:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>C#: TinyUrl conversion code</title>
		<link>http://www.failboy.net/2009/05/c-tinyurl-conversion-code/</link>
		<comments>http://www.failboy.net/2009/05/c-tinyurl-conversion-code/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:23:49 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[TinyUrl]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=7</guid>
		<description><![CDATA[I am currently working on a small project using ASP.Net MVC and I want to incorporate a TinyUrl facility such as that of www.tinyurl.com and the million other clones there are. I found this awesome piece of code that does the trick beautifully! I found the code @ http://blogs.msdn.com/bramveen/archive/2009/01/06/converting-url-to-tinyurl-in-c.aspx It was really quick to implement [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a small project using ASP.Net MVC and I want to incorporate a TinyUrl facility such as that of www.tinyurl.com and the million other clones there are. I found this awesome piece of code that does the trick beautifully! I found the code @ <a title="TinyUrl code" href="http://blogs.msdn.com/bramveen/archive/2009/01/06/converting-url-to-tinyurl-in-c.aspx" target="_blank">http://blogs.msdn.com/bramveen/archive/2009/01/06/converting-url-to-tinyurl-in-c.aspx</a></p>
<p>It was really quick to implement and works really nicely.</p>
<pre class="code"><span style="color: blue;">protected string </span>ToTinyURLS(<span style="color: blue;">string </span>txt)
{
    <span style="color: #2b91af;">Regex </span>regx = <span style="color: blue;">new </span><span style="color: #2b91af;">Regex</span>(<span style="color: #a31515;">"http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?"</span>, <span style="color: #2b91af;">RegexOptions</span>.IgnoreCase);

    <span style="color: #2b91af;">MatchCollection </span>mactches = regx.Matches(txt);

    <span style="color: blue;">foreach </span>(<span style="color: #2b91af;">Match </span>match <span style="color: blue;">in </span>mactches)
    {
        <span style="color: blue;">string </span>tURL = MakeTinyUrl(match.Value);
        txt = txt.Replace(match.Value, tURL);
    }

    <span style="color: blue;">return </span>txt;
}

<span style="color: blue;">public static string </span>MakeTinyUrl(<span style="color: blue;">string </span>Url)
{
    <span style="color: blue;">try
    </span>{
        <span style="color: blue;">if </span>(Url.Length &lt;= 12)
        {
            <span style="color: blue;">return </span>Url;
        }
        <span style="color: blue;">if </span>(!Url.ToLower().StartsWith(<span style="color: #a31515;">"http"</span>) &amp;&amp; !Url.ToLower().StartsWith(<span style="color: #a31515;">"ftp"</span>))
        {
            Url = <span style="color: #a31515;">"http://" </span>+ Url;
        }
        <span style="color: blue;">var </span>request = <span style="color: #2b91af;">WebRequest</span>.Create(<span style="color: #a31515;">"http://tinyurl.com/api-create.php?url=" </span>+ Url);
        <span style="color: blue;">var </span>res = request.GetResponse();
        <span style="color: blue;">string </span>text;
        <span style="color: blue;">using </span>(<span style="color: blue;">var </span>reader = <span style="color: blue;">new </span><span style="color: #2b91af;">StreamReader</span>(res.GetResponseStream()))
        {
            text = reader.ReadToEnd();
        }
        <span style="color: blue;">return </span>text;
    }
    <span style="color: blue;">catch </span>(<span style="color: #2b91af;">Exception</span>)
    {
        <span style="color: blue;">return </span>Url;
    }
}</pre>
<p>Hope this can as useful to you as it was for me!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/c-tinyurl-conversion-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
