The elusive list of icons for visual studio plugins/addins

I love Microsoft but sometimes they just don’t make it easy.  The documentation for visual studio add-in development talks about passing an Id of the icon you want to use when adding new commands to visual studio menus but they never tell you where to find that list of icons.  From the MSDN documentation for Commands.AddNamedCommand Method:

MSOButton
Type: System.Boolean
Required. Indicates whether the named command’s button picture is an Office picture. True = button. If MSOButton is False, then Bitmap is the ID of a 16×16 bitmap resource (but not an icon resource) in a Visual C++ resource DLL that must reside in a folder with the language’s locale identifier (1033 for English).
Bitmap
Type: System.Int32
Optional. The ID of a bitmap to display on the button.

Luckily, someone else on the internet has stepped up and done the work.  Here is a link to their site:

http://www.kebabshopblues.co.uk/2007/01/04/visual-studio-2005-tools-for-office-commandbarbutton-faceid-property/

Posted in Programming | Tagged , , , | Leave a comment

The mobile answer for those using ext.net

Ext.net is by far the best java script client side library out there for ASP.net developers but it is a bit heavy to use on mobile devices.  Thanks to this project there is now a Ext.net type solution for the mobile space!

http://touchnet.codeplex.com/

Posted in Programming | Tagged | Leave a comment

How to use a ConfigurationElementCollection with custom attributes

The other day I was working on a utility class that did xslt transformations and I wanted to make it read some file paths from the app/web.config file.  I found some great examples on the web about using custom configuration sections for .Net 2.0 (just seach google for “custom config sections”) but then I hit a road block when I wanted my config section to look like this:

<XSLTTransformDefinitions>    <– Inherits ConfigurationSection        
         <TransformGroups>       <– Inherits ConfigurationElementCollection        
                 <TransformGroup GroupName=”Foo”>    <– Inherits ConfigurationElementCollection

                  <Transforms>        
                          <Transform Name=”Foo1″ FilePath=”aklsdjf”/>  <– Inherits ConfigurationElement
                          <Transform Name=”Foo2″ FilePath=”asdfjalsd;fj”/>
                          <Transform Name=”Foo3″ FilePath=”alsjfajklsd”/>
                 </Transforms>
                 <Transforms GroupName=”Bar”>
                          <Transform Name=”Bar1″ FilePath=”aklsdjf”/>
                          <Transform Name=”Bar2″ FilePath=”asdfjalsd;fj”/>
                 </Transforms>

             </TransformGroup>
         </TransformGroups>
</XSLTTransformDefinitions>

Everything was going great until i realized that I needed to have two layers of collections, I needed my first collection (TransformGroup) to have an attribute that I could use as an identification key later on in the code.  No matter what I did I could not get the configuration manager to read the custom attribute on the “TransformGroup” configurationelementcollection.  When you want a property read by the configuration manager during the GetSection call you are suppose to just add the “ConfigurationProperty” attribute to your property statement in your class like so:

<ConfigurationProperty("Name", IsKey:=True, isrequired:=True)> _
Public Property Name() As String
         Get
                Return DirectCast(Me("Name"), String)
         End Get
         Set(ByVal value As String)
                Me("Name") = value
         End Set
End Property

This works fine when you inherit from the configurationelement and you get access to the base collection via the Me(“SomeAttributeName”) statements  but when you try the same thing in a class that inherits from configurationelementcollection you get an error because the base collection contains in this case “Transform” elements, not attributes read from the element.  After some time of searching and a little bit of trial and error I figured out a hack.  What you have to do is use the “OnDeserializeUnrecognizedAttribute” method.  You can override this method in you class and when the configuration manager finds any attributes on your xml that are not defined by a class somewhere it calls this method allowing you to do something with what it found.  For my solution I just created a property on my “TransformGroup” class called group name and did not add any code attributes to it, then I overrided the method like this:

Protected Overrides Function OnDeserializeUnrecognizedAttribute(ByVal name As String, ByVal value As String) As Boolean
        If (name = "GroupName") Then
               Me._GroupName = value
               Return True
        End If
        Return MyBase.OnDeserializeUnrecognizedAttribute(name, value)
End Function

It is a bit of a hack but it works.  All you have to do is return true from this function, otherwise .Net will throw an exception.

Posted in My Articles | Tagged , | Leave a comment

How to make a CheckBox fire the ItemCommand Event of a Repeater

At work today I tried to do something I though would be simple, I needed to add a check box control to a repeater’s item template and have it fire the ItemCommand event on the repeater.  The button and link button controls do this without a problem but for some reason Microsoft decided that the check box was going to be different.  Luckily we have great tools like Reflector to help in situations like this, if you dig into the Repeater’s source code you will find out that the ItemCommand event gets fired by event bubbling.  When you add a button or link button to a repeaters template and click on it it will eventually run this code as part of it’s post back.

protected virtual void RaisePostBackEvent(string eventArgument)
{
     base.ValidateEvent(this.UniqueID, eventArgument);
     if (this.CausesValidation)
     {
         this.Page.Validate(this.ValidationGroup);
     }
     this.OnClick(EventArgs.Empty);
     this.OnCommand(new CommandEventArgs(this.CommandName, this.CommandArgument));
}

Notice how the last line in this code calls “this.OnCommand” and passes a CommandEventArgs instance with command name and command argument.  The button and link button have this extra code while the checkbox does not.  The code for this method looks like this:

protected virtual void OnCommand(CommandEventArgs e)
{
    CommandEventHandler handler = (CommandEventHandler) base.Events[EventCommand];
    if (handler != null)
    {
        handler(this, e);
    }
    base.RaiseBubbleEvent(this, e);
}

All the magic that makes the button and link button work is right here.  Calling “base.RaiseBubbleEvent” and passing it the same CommandEventArgs from above allows the repeater control to catch this event later on in its OnBubbleEvent.  The on bubble event for the repeater looks like this:

protected override bool OnBubbleEvent(object sender, EventArgs e)
{
    bool flag = false;
    if (e is RepeaterCommandEventArgs)
    {
        this.OnItemCommand((RepeaterCommandEventArgs) e);
        flag = true;
    }
    return flag;
}

The ItemCommand event is only fired here and only if the eventargs type is RepeaterCommandEventArgs.  Since the standard CheckBox control does not call the RaiseBubbleEvent like a button or link button it’s checkchanged event will never make it here.  But there is a very simple solution to make it work this way, all you have to do is create a custom checkbox control that calls RaiseBubbleEvent during it’s OnCheckChanged event.  Here is a an example, this CheckBoxRepeaterAware control is the same as a regular CheckBox except for the addition of two properties and an overridden OnCheckChanged event.

public class CheckBoxRepeaterAware : CheckBox
{
   #region Properties

   #region CommandName

   public string CommandName
   {
       get
        {
            if (this.ViewState["CommandName"] == null)
            {
                return string.Empty;
            }
            else
            {
                return this.ViewState["CommandName"] as string;
            }
        }
        set
        {
            this.ViewState["CommandName"] = value;
        }
    }

    #endregion

    #region CommandArgument

    public string CommandArgument
    {
        get
        {
            if (this.ViewState["CommandArgument"] == null)
            {
                return string.Empty;
            }
            else
            {
                return this.ViewState["CommandArgument"] as string;
            }
        }
        set
        {
            this.ViewState["CommandArgument"] = value;
        }
    }

    #endregion

    #endregion

    #region Procedures

    #region On Checked Changed

    protected override void OnCheckedChanged(EventArgs e)
    {
        //create a new event args of type command event args
        CommandEventArgs ce = new CommandEventArgs(this.CommandName, this.CommandArgument);

        //allow the base checkbox to handle the event as normal
        base.OnCheckedChanged(e);

        //raise the contorls method RaiseBubbleEvent
        base.RaiseBubbleEvent(this, ce);

    }
    #endregion

    #endregion

}

As you can tell, in the OnCheckChanged event we are calling “base.RaiseBubbleEvent” and passing it the command name and command argument.  By doing this, the repeater will be able to fire it’s ItemCommand event for us.  Again, I am not sure why Microsoft didn’t just implement this in the first place for the check box control but at least the framework is flexible enough that we can do it now.  The last thing we need to do to make this solution even easier is add a tag mapping in our web config to allow the new CheckBoxRepeaterAware control to replace all instances of CheckBox controls in our application.  To do that we add the following to the web config inside the pages node:

<tagMapping>
    <add tagType="System.Web.UI.WebControls.CheckBox" mappedTagType="CheckBoxRepeaterAwareDemo.Classes.CheckBoxRepeaterAware"/>
</tagMapping>
Posted in My Articles | Tagged , , | 2 Comments

Seriously Funny Stuff

My favorite part is the pants at the end Smile

Posted in Uncategorized | Tagged | Leave a comment

Admin Scripting Utils (Free)

http://www.autoitscript.com/autoit3/index.shtml

Frank Wisniewski  

Posted in Uncategorized | Tagged | Leave a comment

Extjs Theme Builder

http://extbuilder.dynalias.com/springapp/mainpage.htm

when it is available, see thread:

http://extui.com/forum/showthread.php?t=79679

Frank Wisniewski  

Posted in Uncategorized | Tagged | Leave a comment

How to do custom expression building for ASP.Net pages

http://www.codeproject.com/KB/aspnet/CustomExpressionBuilder.aspx

Frank Wisniewski  

Posted in Uncategorized | Tagged | Leave a comment

Free Screen Recording with Video

Looks good and is the right price, Free!

http://camstudio.org/

Frank Wisniewski  

Posted in Uncategorized | Tagged | Leave a comment

Jquery Event Calendar

For rescue assistant I was looking for options to provide a scheduling calendar and this is what I found, looks very promising.

 

http://arshaw.com/fullcalendar/

Frank Wisniewski  

Posted in Uncategorized | Tagged | Leave a comment