Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C#
Article

IE Advanced Toolbar for Favorite site navigation and log-in

Rate me:
Please Sign up or sign in to vote.
2.76/5 (11 votes)
23 Jan 20053 min read 132.6K   3.7K   88   22
Advanced IE toolbar, using .NET band objects, for navigation and login with a single click.

Sample Image - IE_Advanced_Toolbar.jpg

Introduction

When you want to access your yahoo mail account, you go to mail.yahoo.com, type in your user name and password and click "Sign In" button. You can select Remember my ID on yahoo to save typing user name but still this is too much of work. If you switch to a different machine you will have to do it again. In this article, I will show you how to add a toolbar to Internet Explorer which will navigate to your favorite Web site(mail.yahoo.com) and do the login for you. Copying some files to other machine will add the toolbar buttons on other machine as well.

Background

Basic framework for this tutorial for adding toolbar to Internet Explorer is copied from Pavel Zolnikov's article on band objects. I suggest you to read this article to understand BandObjects and how you can add Explorer Bar /Toolbar to Internet Explorer. I extended his SampleBar to add auto-login functionality.

Using Toolbar

You can either use the setup.exe for setting up the toolbar on your machine or you can download the source code and build the project. Once you have this toolbar in IE, you can navigate to your favourite website for which you want single click login, say mail.yahoo.com.

  1. Click on Customize button of the toolbar which will bring up a Customize form with all the links, and controls in this website.
  2. In Button Title/Tooltip edit control, enter for the button title for this website, say xyz@yahoo.
  3. In the list box, you will see the entry login. Select it and enter your login name in value edit control and select Add button (Action for entering your username).
  4. Select passwd and enter your password and select Add button (Action for entering your password).
  5. Select Sign In and select Add button (Action for clicking on Sign In button).
  6. Select Ok button to make this button entry to IE toolbar.

Now whenever you click on this button, first IE will navigate to mail.yahoo.com and login in with above login details. The user name, password you entered are kept in an XML file in C:\IE AutoComplete directory. This is a simple text file so username and password are not protected, please don't use this toolbar for your banking websites. I have not added any encryption to it but if you want to modify the source code, then do it.

To remove any button entry from the toolbar, delete the respective file from C:\IE AutoComplete directory. To add these same entry to other computer just copy this directory contents. Toolbar reads all the files in this directory to create configurated buttons.

Using the code

  1. I used Extending Explorer with Band Objects using .NET and Windows Forms to create a user control which will host IE toolbar. I modified Pavel Zolnikov 's SampleBars.sln. In HelloWorld class, button1 is replaced with a ToolBar control myToolBar.
  2. Reference to Microsoft.mshtml.dll is necessary to access HTMLDocumentClass, HTMLAnchorElementClass, IHTMLInputElement. Also put the following lines at the beginning of HelloWorldBar.cs:
    C#
    using mshtml;
  3. A Customize button is added to this toolbar. The click event of this toolbar will iterate through active document to collect all the links, buttons, and input boxes on page. Explorer.Document is instance of currently loaded HTMLDocumentClass.
    C#
    //Explorer.IWebBrowser_Document. HTMLDocumentClass doc = 
          (HTMLDocumentClass)Explorer.Document;

    Two classes ItemType and ButtonEntry are defined in Interface.cs file. ItemType class instance is used for item details on a webpage. ButtonEntry class is used to read/write customized XML button entry data to file system. All these HTMLAnchorElementClass and HTMLInputElementClass objects are added to customize Items' ArrayList of type ItemType. Customize form is displayed for user input.

    C#
    private void onCustomize(object sender, System.EventArgs e)
    {
      //Explorer.IWebBrowser_Document. HTMLDocumentClass doc = 
      //           (HTMLDocumentClass)Explorer.Document;
       
      Customize frm = new Customize(); 
      frm.URL = doc.url; int count = -1; 
      foreach(object o in doc.all)
      {
        try
        {
          count++;
          if( !(o is IHTMLElement))
          {
            continue;
          } 
          IHTMLElement elem = (IHTMLElement)o; 
          if(elem.id == null)
          { 
            if(o is HTMLAnchorElementClass)
              {
                try
                {
                  HTMLAnchorElementClass aElem = (HTMLAnchorElementClass)o;
                  string id = aElem.outerText;
                  string itemInfo = "outterText"; 
                  if(id == null)
                  {
                    id = aElem.href; itemInfo = "href";
                  } 
                  frm.Items.Add(new ItemType("link",id,itemInfo));
                           
                } 
                catch(Exception /*ex_in*/)
                {
                  sp;        
                  {
                    //MessageBox.Show(ex_in.ToString(),"Exception");
                  }
                       
                  continue;
                }
              } 
              if(o is IHTMLInputElement)
              {
                HTMLInputElementClass btn = (HTMLInputElementClass)o;
                try
                {
                  if(btn.type != null)
                  {
                    string type = btn.type.ToLower(); 
                    if(type=="submit" || type == "button" || type == "radio" 
                                 || type == "checkbox" || type == "text" 
                                 || type == "password" )
                    {
                      string id = btn.id;
                      string itemInfo = "id";
                      if(id == null)
                      {
                        id = btn.id; itemInfo = "id";
                      } 
                      if(id == null)
                      {
                        id = btn.name; itemInfo = "name";
                      }
                      string defaultVal = btn.defaultValue; 
                      if(defaultVal != null)
                      { 
                        defaultVal = defaultVal.Trim(); 
                        if(defaultVal == "")
                        { 
                          defaultVal = id;
                        }
                      } 
                      frm.Items.Add(new ItemType(type,id,itemInfo,defaultVal));
                      continue;          
                      continue;
                    }
                  }
                } 
                catch(Exception /*ex_in*/)
                {
                  //MessageBox.Show(ex_in.ToString(),"Exception");
                };       
              }
            }
          } 
          catch(Exception /*eee*/)
          {
            //MessageBox.Show(eee.ToString());
          }
        } 
        if(frm.ShowTheDialog() == DialogResult.OK)
        { 
          addBtn(frm.myButtonEntry);
        };   
      }
       
      return;
    }
  4. On any other button click (xyz@yahoo), if active page is different than mail.yahoo.com, then mail.yahoo.com is loaded. Values are set for all the controls, and any submit button action is invoked to login to particular website.
    C#
    private void myToolBar_ButtonClick(object sender, 
                System.Windows.Forms.ToolBarButtonClickEventArgs e)
    {
      if(myToolBar.Buttons.IndexOf(e.Button) == 0)
      {
        onCustomize(null,null);
        return;
      }
    
      ButtonEntry btnEntry = (ButtonEntry)e.Button.Tag;
    
      onButtonClick(btnEntry);
    }
    
    protected void onButtonClick(ButtonEntry frm_in)
    {
      //Explorer.IWebBrowser_Document.
      HTMLDocumentClass doc = (HTMLDocumentClass)Explorer.Document;
    
      //check for correct site.
      if(frm_in.myURL != doc.url)
      {
        try
        {
          doc.url = frm_in.myURL;
        }
        catch(Exception /*e_in*/)
        {
          //MessageBox.Show(e_in.ToString(),"Exception Caught");
          return;
        }
        Explorer.DocumentComplete+= 
           new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(
           Explorer_DocumentComplete);
        myPendingReqest = frm_in;
        return;
      }
    
      //for each item in UserList fill the values on the active page.
      foreach(ItemType it in frm_in.myArrayLst)
      {
        if(it.Type == "text" || it.Type == "password" )
        {
          try
          {
            //get the item by id.
            HTMLInputElementClass ele = (
                HTMLInputElementClass)doc.getElementById(it.Name);
    
            ele.value = it.Val;
          }
          catch(Exception /*e_e*/)
          {
            //MessageBox.Show("getElementById failed." + e_e.ToString());
          }
        }
        else if(it.Type == "radio" || it.Type == "checkbox" )
        {
          try
          {
            //get the item by id.
            HTMLInputElementClass ele = 
                (HTMLInputElementClass)doc.getElementById(it.Name);
    
            ele.@checked = Convert.ToBoolean(it.Val);
          }
          catch(Exception /*e_e*/)
          {
            //MessageBox.Show("getElementById failed." + e_e.ToString());
          }
        }
        else if(it.Type=="submit" || it.Type == "button")
        {
          try
          {
            //get the item by id.
            HTMLInputElementClass ele = 
               (HTMLInputElementClass)doc.getElementById(it.Name);
            ele.click();
          }
          catch(Exception /*e_e*/)
          {
            //MessageBox.Show("getElementById failed." + e_e.ToString());
          }
        }
      }//end of foreach(string userReq in frm_in.UserListBox)
    }

Pavel Zolnikov's article shows the important part of adding IE toolbar. This article adds feature to modify the IE functionality. As you can see, Accessing/modifying HTML page content from client side is very simple and easy.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralPlease Help - Imposible to build example Interop.SHDcoVw reference to a not safe name Pin
Francisco_morales23-May-11 0:51
Francisco_morales23-May-11 0:51 
Hello, I am trying to build this example but it fails ... Visual studio show me a general assembly error ... reference to a not safe name ...

How can I solve it??

I have read the Pavel Zolnikov article but ... I dont know how to register it

It is the first time thaty I works with COM

thanks lot
GeneralDoesn't display Pin
underscore_dot11-Jan-10 22:04
underscore_dot11-Jan-10 22:04 
QuestionHow to Get Yahoo mail Inbox Message Title Pin
Dabara18-Jun-08 3:55
Dabara18-Jun-08 3:55 
Questiontoolbars Pin
jprakash20808-Jun-08 19:29
jprakash20808-Jun-08 19:29 
QuestionHow to make the toolbar detect mouse clicks on html buttons automatically Pin
manum3-Jun-08 8:23
manum3-Jun-08 8:23 
GeneralToolbar not displayed Pin
sathish1518-Oct-07 3:37
sathish1518-Oct-07 3:37 
GeneralRe: Toolbar not displayed Pin
angelyaya17-Jul-08 23:40
angelyaya17-Jul-08 23:40 
GeneralOnDocumentComplete Pin
mikemcmeekin4-Apr-07 7:02
mikemcmeekin4-Apr-07 7:02 
GeneralRe: OnDocumentComplete Pin
cfenvey3-Apr-08 5:16
cfenvey3-Apr-08 5:16 
QuestionIE Toolbar show up automatically after installing toolbar. Pin
peerahmad3-Apr-07 0:35
peerahmad3-Apr-07 0:35 
GeneralCustom Toolbar Button Pin
rixwan29-Mar-07 3:00
rixwan29-Mar-07 3:00 
QuestionAnyone achieved it? Pin
ALBERTOPAG18-Feb-07 22:31
ALBERTOPAG18-Feb-07 22:31 
GeneralToolBar Installation Pin
Raja Satpathy18-Sep-06 20:06
Raja Satpathy18-Sep-06 20:06 
GeneralIE 7: toolbar unmovable! Pin
joebarthib12-Jun-06 3:13
joebarthib12-Jun-06 3:13 
GeneralRe: IE 7: toolbar unmovable! Pin
MXX23-Oct-06 5:45
MXX23-Oct-06 5:45 
GeneralToolbar location Pin
magdas6-Feb-06 2:44
magdas6-Feb-06 2:44 
Questionwhere is xml file? Pin
Member 43374520-Jul-05 13:20
Member 43374520-Jul-05 13:20 
QuestionCan you done this job like RoboForm? Pin
cjwn15-Jul-05 20:39
cjwn15-Jul-05 20:39 
GeneralDeployment of IE Advanced Toolbar Pin
Anonymous5-Jul-05 7:55
Anonymous5-Jul-05 7:55 
GeneralRe: Deployment of IE Advanced Toolbar Pin
Anonymous6-Jul-05 8:31
Anonymous6-Jul-05 8:31 
GeneralRe: Deployment of IE Advanced Toolbar Pin
Anonymous17-Jul-05 22:31
Anonymous17-Jul-05 22:31 
GeneralRe: Deployment of IE Advanced Toolbar Pin
rixwan31-Aug-07 22:00
rixwan31-Aug-07 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.