Jim Lawless' Blog


A GUI for urlx

Originally published on: Fri, 03 Jul 2009 12:14:25 +0000

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

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



Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks


Previous post: Expanding Shortened URL's
Next post:Obfuscated Perl


About Jim ...


Click **here**
to try out MailWrench;
a command-line SMTP /
SMTPS (Google Gmail)
mailer for Windows.


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

A JavaScript REPL for Android Devices

MailSend is Free

My Blog Engine

The October 10th Bug

A Review of Kevin Mitnick's Book Ghost in the Wires

Spellbound by Web Programming

Backlinks to my Blog Posts

Play MP3 Files with Python on Windows


Random Posts

A Scrolling Banner using Canvas and JavaScript

A Command-Line MP3 Player for Windows

WSH2EXE - The Final Chapter

A Quine in C

Screen Capture from Multiple Monitors in Java

A TCP Command Line Interface in Rhino JavaScript

E-mail cleansing

BSave and BLoad for the Commodore 64

A Simple Media Control Interface Script Processor

We've Moved!


Full List of Posts

http://www.mailsend-online.com/bloglist.htm


Recent Posts from my Other Blog

Remembering Dr. San Guinary

Why Some Web Sites will go Dark on Jan 18th

SNL Superhero Skit

More Ruby Games

My Ruby Game Challenge Entry

Steal this Bookmarklet

Nerd Toys

Learn New Jargon, You Must

Spot the Wiebe

Tech Magazine Glory Days

Book Review : Paull Allen - Idea Man

A 90's Experiment in Online Systems - The U.S. West CommunityLink Service