Direct Threaded Daydreams

A GUI for urlx

July 3, 2009 · 1 Comment

I’ve added a small GUI interface to urlx. The new program is called viewurlx

Enter the original URL in the textbox at the top…

…and click “Expand”

You should see a result such as:

viewurlx.cs

// ViewURLX.cs - Simple Winforms utility to expand shortened URL's.
// and display them.
//
// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

using System ;
using System.IO ;
using System.Net;
using System.Windows.Forms;

namespace ViewURLX
{
   public class ViewURLX : System.Windows.Forms.Form
   {
      private System.Windows.Forms.Label lblOrigURL;
      private System.Windows.Forms.TextBox txtOrigURL;
      private System.Windows.Forms.Label lblEndURL;
      private System.Windows.Forms.TextBox txtEndURL;
      private System.Windows.Forms.Button btnExpand;
      private System.ComponentModel.Container components = null;

      public ViewURLX()
      {
         this.lblOrigURL = new System.Windows.Forms.Label();
         this.txtOrigURL = new System.Windows.Forms.TextBox();
         this.lblEndURL = new System.Windows.Forms.Label();
         this.txtEndURL = new System.Windows.Forms.TextBox();
         this.btnExpand = new System.Windows.Forms.Button();

         this.SuspendLayout();

         this.lblOrigURL.AutoSize = true;
         this.lblOrigURL.Location = new System.Drawing.Point(16, 16);
         this.lblOrigURL.Name = "lblOrigURL";
         this.lblOrigURL.Size = new System.Drawing.Size(30, 13);
         this.lblOrigURL.TabIndex = 0;
         this.lblOrigURL.Text = "Original URL:";

         this.txtOrigURL.Location = new System.Drawing.Point(100, 13);
         this.txtOrigURL.MaxLength = 327670;
         this.txtOrigURL.Multiline = false;
         this.txtOrigURL.Name = "txtOrigURL";
         this.txtOrigURL.ReadOnly = false;
         this.txtOrigURL.ScrollBars = System.Windows.Forms.ScrollBars.Both;
         this.txtOrigURL.Size = new System.Drawing.Size(480, 20);
         this.txtOrigURL.TabIndex = 1;
         this.txtOrigURL.Text = "";

         this.lblEndURL.AutoSize = true;
         this.lblEndURL.Location = new System.Drawing.Point(16, 48);
         this.lblEndURL.Name = "lblEndURL";
         this.lblEndURL.Size = new System.Drawing.Size(30, 13);
         this.lblEndURL.TabIndex = 2;
         this.lblEndURL.Text = "Expanded URL:";

         this.txtEndURL.Location = new System.Drawing.Point(100, 45);
         this.txtEndURL.MaxLength = 327670;
         this.txtEndURL.Multiline = true;
         this.txtEndURL.Name = "txtEndURL";
         this.txtEndURL.ReadOnly = false;
         this.txtEndURL.ScrollBars = System.Windows.Forms.ScrollBars.Both;
         this.txtEndURL.Size = new System.Drawing.Size(480, 80);
         this.txtEndURL.TabIndex = 3;
         this.txtEndURL.Text = "";

         this.btnExpand.CausesValidation = false;
         this.btnExpand.Location = new System.Drawing.Point(270, 160);
         this.btnExpand.Name = "btnExpand";
         this.btnExpand.Size = new System.Drawing.Size(64, 24);
         this.btnExpand.TabIndex = 4;
         this.btnExpand.Text = "Expand";
         this.btnExpand.Click += new System.EventHandler(this.expand);

         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(600, 200);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                     this.lblOrigURL,
                                                                     this.txtOrigURL,
                                                                     this.lblEndURL,
                                                                     this.txtEndURL,
                                                                     this.btnExpand
                                                                      });
         this.Name = "ViewURLX";
         this.Text = "ViewURLX - by Jim Lawless";
         this.Load += new System.EventHandler(this.ViewURLX_Load);
         this.ResumeLayout(false);
      }
      private void ViewURLX_Load(object sender, System.EventArgs e)
      {
      }

      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

      private void expand(object sender, System.EventArgs e)
      {
         txtEndURL.Clear();
         System.Windows.Forms.Cursor.Current =
            System.Windows.Forms.Cursors.WaitCursor;
         try
         {
            HttpWebRequest req =
               (HttpWebRequest)WebRequest.Create (txtOrigURL.Text);
            req.AllowAutoRedirect=true;
            HttpWebResponse res =
               (HttpWebResponse)req.GetResponse ();
            ServicePoint sp = req.ServicePoint;
            txtEndURL.Text= sp.Address.ToString();
         }
         catch(Exception ex)
         {
            MessageBox.Show("Error :" + ex.ToString());
         }
         System.Windows.Forms.Cursor.Current =
            System.Windows.Forms.Cursors.Default;
      }

      public static void Main(string[] args)
      {
         Application.Run(new ViewURLX());
      }
   }
}

You may download the source and .NET 2.0 EXE for viewurlx here:

http://www.mailsend-online.com/wp/viewurlx.zip

del_icio_us Save to del.icio.us
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks


Unless otherwise noted, all code and text entries are Copyright © 2009 by James K. Lawless

Categories: By Language · CSharp
Tagged: , , , ,

1 response so far ↓

Leave a Comment