Click here to Skip to main content
15,882,017 members
Articles / Web Development / ASP.NET
Article

Common Issues & Solutions While Creating Custom ToolBar For IE

Rate me:
Please Sign up or sign in to vote.
4.40/5 (3 votes)
8 Oct 2006CPOL4 min read 43.1K   475   20   8
Solutions For Common Problems While Using Band objects

Introduction

There are a lot of extensions for the wonderful Band Objects

http://www.codeproject.com/csharp/dotnetbandobjects.asp

that Pavel Zolnikov has provided. I have been seeing a lot of queries regarding the implementations and deployment of the toolbars implementing the band objects.Here I will try to describe some common problems that many of us have experienced while working with the band object.

Problem #1 : Creating Strong Names For ActiveX Assemblies

The first problem that I will address here is with regards to the strong names of assemblies.
The strong naming of the BandObjectLib and the Implementing assembly very well in the above mentioned article itself.
The challenge is when the assemblies are copied into the GAC an error that occurs could be

Error 2 Assembly generation failed -- Referenced assembly 'Interop.SHDocVw' does not have a strong name .

This can happen due to the fact that the IE Engine component dosent have a strong name.
This can be resolved by adding the strong name to the SHDocVw through the following statement from the .NET command prompt.

sn -k shdocvw.snk 
AxImp %WINDIR%\System32\shdocvw.dll/keyfile:shdocvw.snk


The first statement will generate a key used for signing the dll and the second statement will create the wrapper assemblies with strong names.

The second statement will result in the wrappers for the IE AxSHDocVw.dll and SHDocVw.dll which could be reffered in place of the earlier files

Problem #2 : IE Custom ToolBar Installer

Creating an installer for the band object is what I will deal with next.
I have created a sample project "ToolBar" for implementing the band objects and a setup project "ToolbarInstaller" for installing the ToolBar.
I will explain the different steps involved in this.

1. The first thing that we will do is Add an installer class to the ToolBar project. Right Click the ToolBar project -> Add New Item -> Installer Class

Image 1

2. The installer class has some events associated with it . Form the designer view go to Properties -> Events ->
and double click on the After Install and the After Uninstall events.

We can use these events to run Regasm utility and Register/Unregister our dlls. The following code could be used to Register the dlls.

C#
private void InstallToolBar_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
{
   try { 
      //Here the Band Object Path will be derived from our 
      //assembly's Location and the name will be replaced 
      
      BandObjectPath = Assembly.GetExecutingAssembly().Location.Remove (
                       Assembly.GetExecutingAssembly().Location.LastIndexOf("//")
                     (Assembly.GetExecutingAssembly().GetName().Name.Length/ + 5));
      BandObjectPath += "//BandObjectLib.dll/"; BandObjectPath = BandObjectPath.Replace(" ",""); 
      ExecAssmPath = Assembly.GetExecutingAssembly().Location.Replace(" ",""); 

      //Start the process "RegAsm" to register the dlls 
      Process.Start (AppPath + "regasm.exe ",BandObjectPath); 
      Process.Start (AppPath + "regasm.exe ", ExecAssmPath); 
  } 
  catch(Exception ex) 
  { 
       EventLog.WriteEntry("Install Exception",ex.Message ); 
  }

Similar code can be used for After UnInstall Function.

3. Now it is time to start the real installation works. First add a new setup project to the solution.Right click on the added setup project go to View -> FileSystem.

Image 2

Right Click on the opened designer AddSpecialFolder -> Global Assembly Cache Folder

Right click on the GAC folder and Add -> Assembly and add the ToolBar as well as the Band

Object Assembly.This will add these assemblies into GAC during installations.

4. In order that the installer class Events to get triggered,We will have to

link the ToolBar dll to the Installer . For that we will right click on the installer project View -> CustomActions

Image 3

Again Right Click on the Installation folder on the designer that opens up and click Add Custom Actions and select the application folder ,
browse for the ToolBar.dll and click OK.

Image 4

This step is to be repeated for the UnInstall folder also.

Problem #3: Packaging .NET FrameWork With Your Application

Till this point we were dealing with installing the applicatio where there is .NET framework installed .What if it is not there .
For that the solution is straight forward.
  1. Download the BootStrapper.exe and install this .
  2. Right Click on the installer Project Go to Properties -> Boot Strapper and select Windows installer BootStrapper.

When your application is getting installed,it will automatically check for the .NET framework and install the same if it is not installed.

Problem #4: Adding ActiveXControls on the ToolBar

Loading an ActiveX controls on the toolbar is another problem that is very commonly faced. The Solution is very straight forward.

  1. Referring to Problem1 , use AxImp utility to add a strong name to the activex dlls
  2. Add these strong named Dlls to the GAC Using the gacutil
  3. Say Your Application is located at C:\MyToolBar

Go to the .NET Command prompt (Start -> ProgramFiles ->VisulaStudio.NET---- ->VisualStudio.NETTools -> Visual Studio .NET Command Prompt) and type

gacutil /if C:\MyToolBar\bin\debug\ActiveX.dll .

If you are using the above installer add the dlls into the GAC using the 3 rd step in Problem #2.

Limitations:

Using the installer that i have created , it is not possible to install the toolbar in C:\Program Files\...
This is Because I couldnt find a straightforward method to get the DOS Path from .NET. There is one method GetShortPathName() in Win32 .
Interested people can read more.
The above mentioned installer will work only on .NET 2003 since the app path is taken

private string AppPath = @"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\"; 

The folder will be something different for other versions.

Conclusion:

The Solutions that I have tried to provide maynot be the best and also not the singular ones. All Suggestions /Comments/Criticisms are whole heartedly welcomed. Please do keep posting about the various problems that you people face while creating the IE toolBars So that I can Keep appending to what is done.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


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

Comments and Discussions

 
GeneralVista Pin
cambler12-Jul-07 14:45
cambler12-Jul-07 14:45 
QuestionIE Toolbar show up automatically after installing toolbar. Pin
peerahmad3-Apr-07 0:37
peerahmad3-Apr-07 0:37 
Generaltoolbar does not appear on right-click or in view->toolbars after install Pin
Daryl Sketch20-Dec-06 7:35
Daryl Sketch20-Dec-06 7:35 
GeneralRe: toolbar does not appear on right-click or in view->toolbars after install Pin
shekharSingh00717-Oct-07 23:49
shekharSingh00717-Oct-07 23:49 
Hi,

I am also having same issue, and im new to .net

thanks

-Shekhar

shekhar singh

GeneralRe: toolbar does not appear on right-click or in view->toolbars after install Pin
shekharSingh00718-Oct-07 20:56
shekharSingh00718-Oct-07 20:56 
GeneralRe: toolbar does not appear on right-click or in view->toolbars after install Pin
Nisha Agrawal12-Sep-08 2:54
Nisha Agrawal12-Sep-08 2:54 
GeneralIE7 Issue Pin
MXX22-Oct-06 15:52
MXX22-Oct-06 15:52 
GeneralRe: IE7 Issue Pin
MXX23-Oct-06 5:47
MXX23-Oct-06 5:47 

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.