Monday, December 28, 2009

Programmatically Create a ClickOnce Application Shortcut

A common approach for programmatically creating a shortcut to a ClickOnce application is to copy the “Application Reference” (*.appref-ms) file that was created in the user’s start menu when the application was installed.

The following function will create a ClickOnce Application Shortcut (*.appref-ms) file for the currently running ClickOnce application without coping the file that exists in the user’s start menu:

''' <summary>
''' Creates a ClickOnce application reference (*.appref-ms) file for the
''' currently running ClickOnce application.
'''
</summary>
''' <param name="location">
''' Path, including file name, of the new ClickOnce application reference
''' file to create. File should have an ".appref-ms" extension.
'''
</param>
Public Sub CreateClickOnceShortcut( _
   
ByVal location As String)

   
Dim updateLocation As Uri = _
        Deployment.Application.ApplicationDeployment.CurrentDeployment.UpdateLocation
   
Dim AppSecurityInfo As New Security.Policy.ApplicationSecurityInfo( _
        AppDomain.CurrentDomain.ActivationContext)
   
Dim DeploymentInfo As ApplicationId = AppSecurityInfo.DeploymentId
   
Dim PublicKey As Byte() = DeploymentInfo.PublicKeyToken

   
Using ShortcutFile As New IO.StreamWriter( _
        location,
False, System.Text.Encoding.Unicode)

        ShortcutFile.Write(updateLocation.ToString().Replace(
" ", "%20"))
        ShortcutFile.Write(
"#"c)
        ShortcutFile.Write(DeploymentInfo.Name)
        ShortcutFile.Write(
", Culture=neutral, PublicKeyToken=")

       
For i As Integer = 0 To (PublicKey.Length - 1)
            ShortcutFile.Write(
"{0:x}", PublicKey(i))
       
Next i

        ShortcutFile.Write(
", processorArchitecture=")
        ShortcutFile.Write(DeploymentInfo.ProcessorArchitecture)

        ShortcutFile.Close()

   
End Using

End
Sub

It appears that the ClickOnce application’s manifest must be signed for the shortcut’s application specific icon to appear. If it is not signed, the default application icon appears.

Monday, December 21, 2009

ASP.NET AJAX Control Toolkit Hidden ComboBox Issue

The AJAX ComboBox control that is included in the September 2009 Release of the ASP.NET AJAX Control Toolkit has a problem whenever the control is hidden when the page is initially rendered. The button for the ComboBox control appears as a 1x1 pixel button and the DropDown list is only 1 or 2 pixels high.

The following is a javascript function I wrote that will correct these issues if it is called right after the ComboBox is made visible.

// Resets the ComboBox indicated by the id argument

// that was hidden when the
// page was initially rendered. This method should

// be called right after the
// hidden ComboBox is made visible. This function

// will correct control sizing
// issues that occur when a ComboBox is not visible

// when the page is initially
// rendered.
//
// Parameters:
// id: Name of the ComboBox control to reset.
// --------------------------------------------------

function ResetComboBox(id) { 

    // Get ComboBox 
    var Combo = Sys.Application.findComponent(id);  

    // Get Button Style 
    var ButtonStyle = Combo.get_buttonControl().style;  

    // Reset Button Image 
    ButtonStyle.height = Combo.get_textBoxControl().offsetHeight + 'px'
    ButtonStyle.width = ButtonStyle.height;

    // Reset Options List 
    var OptionListStyle = Combo.get_optionListControl().style; 
    Combo._optionListHeight = null
    Combo._optionListWidth = null
    OptionListStyle.display = 'block';
}

NOTE: I have only tested this with the September 2009 Release of the ASP.NET AJAX Control Toolkit.