Sri Lanka .NET Forum
a mission and a vision with .NET

Twitter tiny url

rated by 0 users
This post has 1 Reply | 2 Followers

Top 50 Contributor
Posts 175
gslakmal Posted: 11-29-2009 9:38 AM

Hi,

I post meesage to twitter using below code

string url =txtTitle.Text +" "+  "http://theredzone.org/BlogDescription.aspx?EntryId=" + EntryId;

                    //Twitter t = new Twitter("webmaster@theredzone.org", "dm63146");
                    Twitter t = new Twitter("theredzoneorg", "dm63146");

                    t.Status.Update(url);

 

I want use tiny url. like twitter use. How can i do that?

 

lakmal

MCTS Senior Software Engineer ASP.Net C#

 

Top 75 Contributor
Posts 118

 public string getShortURL(string Url)

        {

            try

            {

                if (Url.Length <= 30)

                {

                    return Url;

                }

                if (!Url.ToLower().StartsWith("http") && !Url.ToLower().StartsWith("ftp"))

                {

                    Url = "http://" + Url;

                }

                var request = WebRequest.Create("http://tinyurl.com/api-create.php?url=" + Url);

                var res = request.GetResponse();

                string text;

                using (var reader = new StreamReader(res.GetResponseStream()))

                {

                    text = reader.ReadToEnd();

                }

                return text;

            }

            catch (Exception)

            {

                return Url;

            }

        }

Page 1 of 1 (2 items) | RSS
This space is available for you to advertise. Please contact admin@dotnetforum.lk for more details on how to advertise on the .NET Forum.
Copyright © Sri Lanka .NET Forum. All Rights Reserved. Terms of Use | Privacy Policy