Monthly Archives: March 2009

AjaxControlToolkit – How to Remove the Additional Language Files

On a recent project, I wanted to remove all of the additional language folders/files which come with the AjaxControlToolkit binary. That is, the ones which can be seen in the following screenshot:

Toolkit dll with All Localisation Files

Toolkit dll with All Localisation Files

I needed to conserve as much disk space as possible on this project and had no need for any internationalisation.

So, here is how I accomplished that (note: for those who have read my previous post AJAX Control Toolkit – Getting Started, the first 4 steps are the same):

  1. navigate to http://www.codeplex.com/AjaxControlToolkit , and click on the Downloads link (far right of the page).
  2. assuming you are running V3.5 SP1 of the .NET framework, download the dll only zip archive – AjaxControlToolkit-Framework3.5SP1-DllOnly.zip
  3. extract the contents of that archive into a directory on your machine. I created a directory called AJAX Control Toolkit in C:\Program Files, and placed all of the files from the archive in that.
  4. create a new Web Site in Visual Studio 2008.
  5. create a new folder called Bin.
  6. add AjaxControlToolkit.dll (from C:\Program Files\AJAX Control Toolkit) to the Bin folder
  7. add the following element to web.config (inside the <pages><controls></controls><pages> element)

    <add tagPrefix=ajaxToolkitassembly=AjaxControlToolkit namespace=AjaxControlToolkit/>

  8. add a Reference (to the Solution) to the AjaxControlToolkit.dll assembly

I hope this helps anyone else who might have been trying to figure out how to go about this.

How to Insert an Image into an SQL Server Database

There are various ways to insert images into an SQL Server database. The one which I want to talk about here is that which uses the OPENROWSET command. The MSDN documentation refers to it as “a one-time, ad hoc method of connecting and accessing remote data by using OLE DB”. As I am just using SQL Server Management Studio Express to insert the data, OLE DB will do just fine.

The OPENROWSET command includes a built-in BULK provider that enables data from a file to be read and returned as a rowset. You can use this to load data which is located locally on your computer, without having to use any other provider, or requiring any connection information. This makes using it to insert an image quite straightforward.

As an example, the following command inserts an image (located on my Desktop) into the pub_info relation of Microsoft’s sample PUBS database:

INSERT INTO dbo.pub_info (pub_id, logo, pr_info)
SELECT 9998, PhotoToLoad.*, 'this is a good publisher'
FROM OPENROWSET
	(BULK 'C:\Users\USERNAME\Desktop\Screenshot.png', SINGLE_BLOB) PhotoToLoad

The OPENROWSET syntax used above needs to be used as if we were returning data from a table. So, I have used the INSERT INTO…SELECT syntax, which is one of the accepted forms of syntax for the INSERT statement. The above example inserts the values 9998, PhotoToLoad.* and ‘this is a good publisher’ into the attributes pub_id, logo and pr_info respectively. The alias PhotoToLoad is used to enable us to refer to the BULK-loaded data. The datatype of the logo attribute is image.

The other cool thing about this command is that you are not restricted to loading images. You can use it to load any binary data, including music, movies etc. Definitely a handy command for ad-hoc inserts.

Generic List vs Object List

I was reading through a Microsoft certfication training kit book, when I came upon a discussion about the performance of data structures which use generics, against those that use objects (and boxing). Intrigued, I knocked up a couple of Linked List types for a test.

The implementations of the Linked Lists were identical, bar the fact that one used Generics, whilst the other used Objects. I then used 2 successive, long-running for loops, each performing inserts on the respective Linked Lists, to test the performance of each. The System.Diagnostics.Stopwatch() class came in very handy:


static void Main(string[] args)
{
	ObjectNS.LinkedList objectsList = new ObjectNS.LinkedList();
	GenericNS.LinkedList<int> genericLinkedList = new GenericNS.LinkedList<int>();

	//  first, time the performance of genericLinkedList inserts
	System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
	watch.Start();

	for (int i = 0; i < 300000; i++)
		genericLinkedList.Insert(i, genericLinkedList.Count);

	watch.Stop();
	Console.WriteLine("Performance of Generics - {0}", watch.Elapsed.ToString());

	//  second, time the performance of objectsList inserts
	watch.Reset();
	watch.Start();

	for (int i = 0; i < 300000; i++)
		objectsList.Insert(i, objectsList.Count);

	watch.Stop();
	Console.WriteLine("\nPerformance of Object/Casting - {0}", watch.Elapsed.ToString());

	Console.WriteLine("\n\nPress any key to close window");
	Console.Read();
}

And the result:

Generics vs Objects - Performance Comparison
Generics vs Objects – Performance Comparison

So, it looks like the performance penalty of boxing the integers was enough to give generics a clear victory. And of this, I am glad. Generics are very cool and easy to use. So, finding out that they also perform well – that’s icing on the cake.

You can download the whole code for my test here.