This project has moved and is read-only. For the latest updates, please go here.

Camlex.NET Sample Codes in VB.Net

Apr 28, 2011 at 6:38 AM


Can you help me to provide a sample codes written in VB.Net? What I'm trying to achieve is like this example CAML Query.

                  <FieldRef Name='CollaborationType' />
                  <Value Type='Choice'>Test Colla</Value>
                  <FieldRef Name='CollaborationType' />
                  <Value Type='Choice'>Cross asset class deal</Value>
                  <FieldRef Name='DealType' />
                  <Value Type='Choice'>Deals</Value>
                  <FieldRef Name='TeamLeader' />
                  <Value Type='UserMulti'>A</Value>



Apr 28, 2011 at 8:26 AM
Edited Apr 28, 2011 at 8:31 AM

milan1216 hi,

I'm not very good in VB.Net, but can help you to write the code on C# and you can try to migrate it on VB.Net using some existing conversion tools. On C# it will be something like this:


var s = Camlex.Query().Where(x => (x["CollaborationType"] == (DataTypes.Choice)"Test Colla" || x["CollaborationType"] == (DataTypes.Choice)"Cross asset class deal") ||
    (x["DealType"] == (DataTypes.Choice)"Deals") && ((string)x["TeamLeader"]).Contains("A")).ToString();


The only moment is that Contains tag will have Text type for Value instead of "UserMulti" - however it should work with it also.

Apr 28, 2011 at 9:03 AM

one additional thing - currently I'm working over automatic conversion feature from xml -> C#. When it will be ready developers will be able to convert existing CAML xml into Camlex.NET C# expressions automatically (there will be some on line service for this). After that we can consider to add automatic VB.Net conversion to it as well.

Apr 29, 2011 at 8:14 AM


When I tried to converted your C# codes into VB.Net the output is like this:

Dim s = Camlex.Query().Where(Function(x) (x("CollaborationType") = DirectCast("Test Colla", DataTypes.Choice) OrElse x("CollaborationType") = DirectCast("Cross asset class deal", DataTypes.Choice)) OrElse (x("DealType") = DirectCast("Deals", DataTypes.Choice)) AndAlso DirectCast(x("TeamLeader"), String).Contains("A")).ToString()
But my issue is the camlex dll is not accepting string value on this format "DirectCast("Must Be Object Expression", DataTypes.Choice) OrElse"
My value is string or integer.. How can I use the Camlex.Query or do I need to define it first as an expression parameter?

I hope you can help me with this.
Apr 29, 2011 at 9:32 PM

unfortunately I have no VB.Net project templates installed with my VS, so I can't check it. What do you mean by "camlex dll is not accepting string value"? does it throw some run time exception or compilation fails? If compilation fails - what exact error message it shows?

May 3, 2011 at 7:24 AM


The error I got is Value of type 'String' cannot be converted to 'CamlexNet.DataTypes.Choice' 

As you can see on my sample DirectCast(this must be an object expression not a string, DatTypes.Choice)

Or do you have other method to do this?

Thanks for your help.

May 3, 2011 at 11:52 AM
Edited May 3, 2011 at 12:22 PM

I'll try to find environment with VB.Net installed and will reply to you. As workaround you can create C# class library and put the code there.

May 4, 2011 at 3:41 AM


Thanks in advance... I'll wait for that.

May 7, 2011 at 7:59 PM

I checked VB.Net version - seems like this case is not supported here. Even if you will use CType instead of DirectCast - compilation fails with another error. It says that operator = is not defined for object and DataTypes.Choice types. In C# there is assignment operator =, and compare operator ==, so you can use == for reference types object - and it will be compiled, as compiler will use reference equality. But in VB.Net there is only = operator both for assignment and for comparison and it should be defined explicitly somehow. So the only way to use it - is to create C# class library, write code there and use reference on it in your VB.Net project.

May 9, 2011 at 8:44 AM

Ok, at least I have an idea that this dll is not compatible with VB.Net.  Anyway, thanks for your response this will be a big help for me, not to push it on VB.Net since it's not doable.
Best idea is what you've mentioned to create a seperate C# library to invoke this method in

Thanks Sadomovalex.