Blog

Posts written in 2010.

  • Published on
    -
    1 min read

    Replace One Word or Phrase Through An Update Query

    UPDATE queries are great to modify all information stored within our column. But what if we needed to only update a specific phrase or word within our column?

    Well, we can use an UPDATE query along with a REPLACE function. It can be used like this:

    UPDATE <table_name>
    SET <column_name> = Replace(<column_name>, 'old phrase', 'new phrase')
    
  • Published on
    -
    1 min read

    Sign An Assembly In Visual Studio 2003

    I needed to create a custom web part using Visual Studio 2003 for a SharePoint 2003 client intranet, something I have never done before. As fellow SharePoint developers will know, you need to strongly name your project assembly whenever you need deploy a custom made web part.

    Visual Studio 2005 and onwards allows you to easily create a strongly named key through the graphical user interface. In Visual Studio 2003, you will need to use the Visual Studio 2003 Command Prompt. You can find the Visual Studio 2003 Command Prompt by going to: Start > Program Files > Visual Studio 2003 > Visual Studio.NET Tools > Visual Studio .NET 2003 Command Prompt.

    Visual Studio 2003 Command Prompt

    Once the command prompt window has opened all you need to do is enter the following to create a SNK:

    Setting environment for using Microsoft Visual Studio .NET 2003 tools.
    (If you have another version of Visual Studio or Visual C++ installed and wish
    to use its tools from the command line, run vcvars32.bat for that version.)
     
    C:\Documents and Settings\Administrator\Desktop>sn -k MyKey.snk
     
    Microsoft (R) .NET Framework Strong Name Utility  Version 1.1.4322.573
    Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. 
     
    Key pair written to MyKey.snk
     
    C:\Documents and Settings\Administrator\Desktop>
    

    As you can see from my command prompt example above, I am creating a new SNK file called MyKey.snk. This SNK file will be generated on my Desktop.

  • Published on
    -
    1 min read

    Dynamically Load ASP.NET UserControls

    I had created some .NET UserControl’s that I needed to dynamically add to a Panel control within my page. I previously thought generating my UserControl’s dynamically would be the same as dynamically generating any other .NET Control, like this:

    private void CreateControls()
    {
        //Create control
        TextBox txtUser = new TextBox();
        txtUser.ID = "txtUser";
        txtUser.Text = "Please enter a value";
     
        //Add Control to Panel already in our .NET page
        pnlControlPlaceHolder.Controls.Add(txtUser);
    }
    

    But I was wrong! :-)

    Fortunately, there is a really easy way to to add a UserControl dynamically by simply making use of the “LoadControl” method. The “LoadControl” method takes a single parameter containing the virtual path of your UserControl. For example:

    private void CreateControls()
    {
        //Create control
        Control myUserControl = LoadControl("MyUserControl.ascx") as MyUserControl;
        myUserControl.ID = "ucMyControl";
     
        //Add Control to Panel already in our .NET page
        pnlControlPlaceHolder.Controls.Add(myUserControl);
    }
    

    Easy!