Custom Querystring

March 28, 2008

The article on manipulating the query string, which I discussed here, has moved to a new site, and today I noticed, that one statement was not completely correct, but only when I debugged one of my projects.

The NameValueCollection.ToString() only returns the class name, which is the default ToString() behavior.

According to the MSDN documentation, HttpUtility.ParseQueryString() returns a NameValueCollection, but it really is a HTTPValueCollection, which is itself derived from NameValueCollection.

You can create a HTTPValueCollection only through the ParseQueryString() method. However, the big advantage of this class is that the ToString() method is overwritten and returns the key/value pairs in URL notation, i.e. key1=value1&key2=value2 etc.


ASP.Net Page and Control Lifecycle

March 26, 2008

There are many descriptions of ASP.Net page and control lifecycles, but most of them lack the detail of interaction between pages and controls.

I was surprised today by the fact that a UserControl’s OnInit fired before the Page’s OnInit event, which is quite unintuitive. On the other hand, the naming could be more descriptive; does anybody need event names like OnInit, OnPreInit, OnPostInit, OnIntermediateInitButNotQuiteDone ?

Here is the MSDN information on the Page Object Model, Page Lifecycle, and Control Lifecycle. But this information is not really useful when you want to know how pages and masterpages and controls interact.

Unfortunately the internet is full of dead links.

This page offers all the information you need to have, resulting from tracing literally every event an ASP.Net object handles. And this page here gives a graphical representation of the sequence of events.

Enjoy :)


Javascript Dual Listboxes in ASP.Net

March 21, 2008

During the migration of an ASP.Net project to version 2.0 I was looking for a dual listbox control with Javascript support.

Unfortunately, a lot of “hits” led into dead ends and product listings of things long removed from the web.

Then I found the MetaBuilders WebControls collection on CodePlex, which you just need to download and compile. Then add a reference to the DLL in your project, and add the DLL in your component toolbox.

Compiling the latest version (Change Set 15894 of March 6, 2008) in Visual Studio 2005 required a bit of editing though:

First, VS could not open the project, however changing the first line of the .sln file from

Microsoft Visual Studio Solution File, Format Version 10.00

to

Microsoft Visual Studio Solution File, Format Version 9.00

fixed that.

Next, the PollViewDesigner.cs raised an error with an inline initialization of a List object. Since I didn’t need a Poll control, I simply commented out the offending code, compiled the solution, and was ready to use it in my project.

I noticed that the DualList’s behavior differs depending on the value of AutoPostBack.

If AutoPostBack is false, you can move list entries by double-clicking them. If AutoPostBack is true, moving only works by clicking the buttons.

Since some items should always be selected items, I wanted to check the unselected items in the ItemsMoved event, and re-select them if required. Without AutoPostBack, I have to check them in response to an action button instead.


Installing Bugzilla on Windows

March 19, 2008

This article describes the installation of Bugzilla 3.0.3 on Windows Server 2003 R2.

The installation needs to install several Perl modules. The ActiveState ppm manager invokes a GUI application; however I found it easier to use the ppm-shell command to issue the commands in the section “Install Modules”.

Installation of Bugzilla on IIS is described here.

The Perl CGI Extension is not active if IIS is in lock down mode. If that is the case, you will find 404s in the IIS log file, with sub-error code 2, indicating lock down.

On my systems, simply allowing the Perl CGI Extension in IIS Manager was not enough. I had to allow All Unknown CGI Extensions to make Bugzilla work.

Finally, you should bear in mind that Bugzilla writes all configuration data to files in the application directory and its subdirectories (such as ./localconfig, data/params). Therefore you have to grant the IUSR account full access to the application directory (= the directory where the bugzilla virtual directory in IIS points to).


Link List

March 18, 2008

Useful stuff on the web:


Native WinAPI with .Net

March 12, 2008

In a previous post I noted that some WinAPIs can be found on the web by searching for the string NativeMethods, which seems to be a Microsoft standard naming convention.

Today I came across pinvoke.net, a website dedicated to the documentation of WinAPI calls from .Net.

There is even a plugin for Visual Studio (2003 and 2005) that integrates pinvoke’s wiki contents into the IDE.


Retrieving XML Data in SQL Server 2005

March 4, 2008

I recently developed an application, which, among other things, communicates with other already-existing applications via XML files. The files are passed through MQSeries queues and stored in an SQL Server database.

Today I needed to find database records with contain certain XML content, so I thought, OK, that’s SQL Server 2005, it has XML support, so that shouldn’t be a big deal.

The table stores the XML files in an NTEXT column, so I tried

SELECT ID, CAST(XmlFile AS XML) FROM TableName

which gave me an unexpected error message.

Msg 9402, Level 16, State 1, Line 1
XML parsing: line 1, character 43, unable to switch the encoding

True, SQL Server stores my files in Unicode if I declare the column ntext. But how should I ever be able to store foreign XML documents, if the server can’t handle them? Ignoring the encoding attribute would be very nice in that case.

Next step: try to get rid of the encoding attribute. Easy, just replace it with an empty string:

SELECT ID, CAST(REPLACE(XmlFile, encoding="ISO-8859-1"', '') AS XML) ...

with the undesired side-effect, that *any* occurrence would be replace, not just the one within the ?xml? declaration.

Luckily, that didn’t work either:

Msg 8116, Level 16, State 1, Line 1
Argument data type ntext is invalid for argument 1 of replace function.

You’d expect that, since ntext and nvarchar(max) *behave* the same (i.e. unlimited Unicode strings), functions operating on them shouldn’t make a difference either.

Finally, my solution looked like this:

SELECT ID, CAST(
	REPLACE(CAST(XmlFile AS NVARCHAR(MAX)), 'encoding="ISO-8859-1"', '')
	AS XML).query('xpath to nodes') AS Node
FROM TableName

Should I be happy that this works, or angry that there’s no simpler way to do it?


Follow

Get every new post delivered to your Inbox.