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

del_icio_us Save to del.icio.us
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


Search this Blog (and site)

Search this Site with PicoSearch


Subscribe to this Blog

 Subscribe!


Contact Me

Email: jimbo@radiks.net


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

Mad Schemes : Learning Lisp via SICP

Auto Save Clipboard Images Redux

Extending SpiderMonkey JavaScript on Windows

Rhino JavaScript to EXE with launch4j

Compiling Rhino JavaScript to Java

Directory Traversal in Rhino JavaScript

Taking Shape

We've Moved!


Popular Posts

A Command-Line MP3 Player for Windows

Auto Save Images from the Clipboard

Java in a Windows EXE with launch4j

An Interview with Tom Zimmer: Forth System Developer

Setting Windows Console Text Colors in C


Random Posts

Site Tracking with Perl

A DSL in JavaScript

Flirting with Forth

Along Came AWK

Envy

Windows Text to Speech in WSH JavaScript

A Command Line Scheduler

A Command-Line CD Tray Opener

TAP : A Command Processor Library

We've Moved!


Full List of Posts

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


Blogroll

MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer