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

Retrieving My Items

May 10, 2010 at 5:03 PM

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

It went like this...

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

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

May 11, 2010 at 4:11 PM
Edited May 11, 2010 at 4: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 = 
        .Where(x => x["Editor"] == (DataTypes.User)"Administrator").ToString();

It renders:

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

I hope it helps.
May 11, 2010 at 4: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 1: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.