Retrieving My Items

May 10, 2010 at 4:03 PM

When I developed some CAML by hand, there was a way to incorporate the [ME] functionality.

It went like this...

<Eq>
    <FieldRef Name="AssignedTo" />
    <Value Type="Integer"><UserID Type="Integer"/></Value>
</Eq>

How would you create an expression in CAMLEX.Net like that?

Developer
May 11, 2010 at 3:11 PM
Edited May 11, 2010 at 3:12 PM

Exactly this syntax not supported yet. But there is similar thing.

You could use DataTypes.User enumeration value to indicate that you are working with type="User". Example on Home page says:

var caml = 
    Camlex.Query()
        .Where(x => x["Editor"] == (DataTypes.User)"Administrator").ToString();

It renders:

<Where>
  <Eq>
    <FieldRef Name="Editor" />
    <Value Type="User">Administrator</Value>
  </Eq>
</Where>

I hope it helps.
Coordinator
May 11, 2010 at 3:27 PM

hello, chorpeac

as Vladimir said you can use so called string based syntax for querying by user. Instead of hardcoded "Administrator" value you can use SPContext.Current.Web.CurrentUser.LoginName in order to get items assigned to currently logged user.

If you want exactly the same CAML query you can customize resulting CAML using Linq2Xml as IQuery interface has ToCaml() method which returns XElement[]:

XElement[] ToCaml(bool includeQueryTag);

but this is less flexible approach

May 12, 2010 at 12:11 AM

Thanks for your replies. I am actually calling these from another .NET app, so your CurrentUser.LoginName would be similar to me getting the LoginName from the  System.Web.HttpContext.Current.User.Identity.Name. It should work the same, I just wanted to see if there was a built in ME shortcut for it.

Thanks!