How to pass arguments to datahandler

Nov 9, 2008 at 1:04 AM
Hi There,
passing this:
<param name="initParams" value="ConfigurationProvider=DarkTheme,DataProvider=XmlDataProvider;Path=DataHandler.ashx?collectionID=2" />

will obviously not work, since it's not a valid key/value pair. Question is, how to pass an argument along for dynamic db querys etc?

My idea was to extend XmlDataProvider.cs to accept something like:
 .. value="ConfigurationProvider=DarkTheme,DataProvider=XmlDataProvider;Path=DataHandler.ashx;collectionID=2"

but I couldn't get it to work.

Anyone have any suggestions or pointers?
Thx in advance!
Nov 12, 2008 at 12:10 PM

you have to modify the file App.xaml.cs. In SplitStartupEventArgs you add

                    if (keyValuePair.Count() == 3)
                        subParams.Add(keyValuePair[0], keyValuePair[1] + "=" + keyValuePair[2]);

Then in the constructor of XmlDataProvider the var xmlPath will have your value "DataHandler.ashx?collectionID=2".


Nov 12, 2008 at 10:05 PM
Hi Olaf,

thx for your reply!
I don't quite understand how "keyValuePair[1] + "=" + keyValuePair[2]" will construct "DataHandler.ashx?collectionID=2", though.
If I understand the code correctly, keyValuePair is an array, so keyValuePair[1] equals {"Path", "Datahandler.ashx"} and keyValuePair[2] equals {"collectionID", "2'} ...

Don't get it - what am I missing here?

Once again, Thx!
Nov 13, 2008 at 6:44 AM
Hi Marcus,

the params are something like "DataProvider=foo;Path=bar". This is first split via .Split(';') to "DataProvider=foo" and "Path=bar". Then these two are split via .Split("=") to "DataProvider" (the first key), "foo" (the first value), "Path" (the second key) and "bar" (the second value). But when "Path=bar" contains something like "Path=bar?ID=2" then it will be splitted to keyValuePair[0] = "Path", keyValuePair[1] = "bar?ID" and keyValuePair[2] = "2". No one expected the value containing a "="! So keyValuePair[1] + "=" + keyValuePair[2] will result to "bar?ID=2".

Maybe it has to be modified again when someone wants to have i.e. "Path=DataHandler.ashx?album=2&slide=5" ...


Nov 20, 2008 at 11:57 PM
Hi Olaf,

forgot to thank you for your help and suggestions - got it working.

Thx again!
May 21, 2009 at 6:04 PM

This worked for me!! Thanks!