in

dotNetFreak

Ramblings & Controls from a .NET Addicted Freak!

Kevin Gearing's Blog

July 2004 - Posts

  • Executing the System Information Program

    Following up on my last post, it can also be helpful to have the ability to launch the Microsoft System Information program from within your application, so should any users have difficulty they're able to provide you with various information within a couple of clicks...

    Imports System.IO
    Imports Microsoft.Win32

    Private Sub RunSysInfo()

    'Try to retrieve the location from the registry

    Dim path As String = GetHklmValue("SOFTWARE\Microsoft\Shared Tools\MSINFO", "PATH")

    'Try again using a different registry key if the location wasn't found

    If path = String.Empty Then

    path = Registry.GetHklmValue("SOFTWARE\Microsoft\Shared Tools Location", "MSINFO") If path <> String.Empty Then path += "\MSINFO32.EXE"

    End If

    'If we have found the location and the program exists, run it

    If path <> String.Empty Then

    If File.Exists(path) Then

    Process.Start(path)

    Exit Sub

    End If

    End If

    'Inform the user we were unable to locate the program

    MessageBox.Show("Unable to locate the System Information program.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

    End Sub

    Private Function GetHklmValue(ByVal keyName As String, ByVal subKeyName As String) As String

    Try

    Return CStr(Registry.LocalMachine.OpenSubKey(keyName).GetValue(subKeyName, ""))

    Catch ex As System.Exception

    Return String.Empty

    End Try

    End Function

  • Determining the Build Date of an Assembly

    Sometimes it can be quite handy to display the build date of an assembly in an 'About' window or similar. After reading a couple of threads on how it can be calculated from the build and revision numbers, below is a very simple function to produce the build date for the currently executing assembly.

    This ONLY works if the assembly was built using VS.NET and the assembly version attribute is set to something like the below. The asterisk (*) is the important part, as if present, VS.NET generates both the build and revision numbers automatically.

    <Assembly: AssemblyVersion("1.0.*")>

    The code...

    Private Function BuildDate() As Date

    'Build dates start from 01/01/2000

    Dim result As Date = #1/1/2000#

    'Retrieve the version information from the assembly from which this code is being executed

    Dim version As System.Version = System.Reflection.Assembly.GetExecutingAssembly.GetName.Version

    'Add the number of days (build)

    result.AddDays(version.Build)

    'Add the number of seconds since midnight (revision) multiplied by 2

    result.AddSeconds(version.Revision * 2)

    'If we're currently in daylight saving time add an extra hour

    If TimeZone.IsDaylightSavingTime(Now, TimeZone.CurrentTimeZone.GetDaylightChanges(Now.Year)) Then result.AddHours(1)

    Return result

    End Function

    An alternative method is to simply read the last time the file was written, using something similar to:

    Return System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly.Location)

  • New Control - CasedTextBox - Sets TextBox Character Case

    Unlike Windows Forms.NET, ASP.NET textbox controls seem to be missing the 'Character Casing' property which allows you to define the case of characters entered within a textbox.

    Whilst it's fairly easy to replicate by hooking up some JavaScript to the 'onblur event', e.g.

    txtEMailAddress.Attributes.Add("onblur", "this.value = this.value.toLowerCase();");

    it becomes a bit of a pain having to enter this on every page. So, below is a simple ASP.NET control that basically does it for you. It simply inherits from the standard TextBox class and adds a new 'Character Casing' property allowing you to set the character case to one of three options:


    Features:

    • CharacterCasing property to set the case to upper (all characters uppercase), upper first (only the first character uppercase) or lower (all characters lowercase).
    • Full Visual Studio .NET designer integration.


    Usage:

    Simply download, add to your toolbox, drag 'n' drop to your page and set the property using the property grid.


    Licensing & Download:

    Free for both personal and commercial use, however please consider donating!

    You may also redistribute the control royalty free, providing that you don't charge for it. Also, if you intend to distribute the control as part of an application which is publicly available it would be nice to know, although this isn't a requirement.

    To download, please visit the 'Downloads' area.

     


    Help & Support:

    Please post in the forum.

     

    Revision History:

    Updated 05/06/2007 (v2.0.0):

    Click here for details.

    Updated 29/10/2004 (v1.0.0):

    • Namespace changed from dotNetFreak.WebControls.UI to dotNetFreak.WebControls.
    • Much improved designer integration.
    • Property values are now stored in ViewState.
    • OnPreRender bug fixed.
    • Assembly is now signed with a Strong Name.
Copyright ©2004-2007 Kevin Gearing. All Rights Reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems