Getting items by user

Jun 19, 2010 at 4:24 AM

I have a list where the Created By column is setup to display as Name (with presence). I want to be able to retrieve the list items that where created by the user visiting the site. However, I only know the user's login name, but the login name is a part of the data in the created by column. I thought I would be able to use this type of caml...

Camlex.Query().Where(x=> x["Author"] == (DataTypes.User)"loginname")

That didn't return anything though. So I figured, I would change the SP column to account instead of Name(with presence). That worked! So it looks like the caml needs to be an exact match.

If I don't want to or can't change the column like that, is there a structured caml to do this?

How do you return a list of items by user name not user type?

Jun 21, 2010 at 12:57 PM

Thanks for your investigation!

If I understood you correctly, you had a field with type = "User". Also initially, the field had a representation as "Name (with presence)". And, at that moment, you were NOT able to retrieve any results with Camlex.NET using syntax:

Camlex.Query().Where(x => x["CreatedBy"] == (DataTypes.User)"loginname")

Then you changed the representation of the field from "Name (with presence)" to "Account" (still having the type of the field as "User"), and then Camlex.NET started to retrieve items successfully.

I checked such situation and for me it worked fine in both cases - having the representation as "Name (withpresence)" as well as "Account". And from logical point of view, it is OK, because the background storage (determined by the field type = "User") is not affected by the representation (which affects only how the field should look like). So, in both cases, the way (in which the user value is stored) is the same - and as the result, CAML request should work similarily.

Did you use fully qualified account name (like "DOMAIN\LoginName") or only login name (like "LoginName")? In the last case, CAML will not work.

Jun 21, 2010 at 3:27 PM
Edited Jun 21, 2010 at 4:07 PM

Thanks for checking on this for me. I did a little more investigation, and I was only sending the userkey(loginname) in the query. I changed it to include the FQ login name (domain\loginname), but I still did not get the expected results.

I don't think this is a CAMLEX.Net issue, because I loaded up the U2U CAML Query Builder to try some user queries. The user queries only returned results when the query contained text that was visible in the SP list.


When User Field was Name (with Presence): Queries with contains(user last name or first name) worked fine, Queries with userkey or email returned nothing.

When User Field was Account: Queries with domain\loginname worked fine.

I think this is a "feature" of sharepoint??

But it works for you?

Here is the only thing I found that comes close, and I don't think you can do this right now in CAMLEX, right?