web 2.0

List's column internal name - Update

An easier way to get the internal name of a List Item field (than the one mentioned here) is by using the 'Internal Name' property of an item field.

For example:

SPList spList = spWeb.Lists["List Name"];

string fieldInternalName = spList.Fields["Field Name"].InternalName

This will give you the internal name of the column in the list. The internal name is used in CAML queries while querying on a column in the list.

This means you don't have to bother converting your List column name special characters to get the internal name, since you get the internal name that has already converted the special characters for you.

Tags: ,

CAML | Lists

CAML query for retrieving ListItems where fieldType is 'User'

Had a hard time searching for a CAML query to retrieve ListItems where Column Type was 'Person or Group'. The below piece of code will retrieve ListItems containing the user based on the user's Display name. I'm still looking for a way to search based on the user's Logon Name 

string camlQuery = "<Where><Eq><FieldRef Name='User_x0020_Name'/><Value Type='User'>" + userDisplayName + "</Value></Eq></Where>"

SPList spList = spWeb.Lists["List Name"];

SPQuery spQuery = new SPQuery(spList.Views["All Items"]); 

spQuery.Query = camlQuery;

SPListItemCollection listItemCollection = spList.GetItems(spQuery);

  

Update: Lists can be searched on the Logon Name if the Type of Display for the 'Person or Group' Column type is changed to 'Account' (which basically displays the Logon Name in the 'DOMAIN NAME\Logon Name' format)

Tags: ,

CAML | Lists