It is not

A quick way to programmatically post to twitter is to create a URL that posts directly to their web site. This little tidbit you can find on several other blog posts out there: (link this one). Here is the C# code I am using to launch the default browser from a Winform application:

private void twitterToolStripButton_Click(object sender, EventArgs e)
    Cursor.Current = Cursors.WaitCursor;

    Uri twitterUri = new Uri(String.Format(

        Cursor.Current = Cursors.Default;

This works nicely even when the Tweet has hash marks (#) etc… -- because of the HttpUtility.UrlEncode. However, in the original code I was going to instead of which is a problem – since the subnet of www redirects to the and gives the original encoding another layer of encoding. I am not sure if this is an issue with twitter (which might be fixed) or the browser (which will probably never be fixed). Going to creates garbage in the text area of the post like this:




Notice that in the picture the address bar has already redirected and added the extra encoding.




The moral of the story, make sure you are going to, and not when posting with this technique.




  1. Uri.ToString can unescape characters that are necessary to interpret the URI correctly on the destination server; use Uri.AbsoluteUri instead to make sure the URI doesn't get corrupted.

    See for more information.


Post a Comment

Popular posts from this blog

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

Yet once more into the breech (of altered programming logic)

How to convert SVG data to a Png Image file Using InkScape