0
votes


I have sharepoint 2013 list "Employee" which contents folders with the contact information of employees. There is a field which helps to identify the each employee: Employee GUID. This field has type "Text" and format (example): a3c73e48-d38e-4c83-8ed4-df70d3037cc2.

I want to use query to find employee with guid which i want. I use the code bellow:

string guid = "a3c73e48-d38e-4c83-8ed4-df70d3037cc2";
string sQuery = @"<Where><Eq><FieldRef Name=""Title""></FieldRef><Value Type=""Text"">"+guid+"</Value></Eq></Where>";
                    var oQuery = new SPQuery();
                    oQuery.Query = sQuery;
                    oQuery.Folder = folder;

                    SPListItemCollection collListItems = list.GetItems(oQuery);

And in collListItems.Count i received 0 !

But in camlQueryBuilder i receive the employee. And if i use Text field: last name + second name to identify the item i receive the collection of items with such last name + second name and there i found my employee with guid which i want.

What i do wrong? Explain me please!

1

1 Answers

0
votes

Your CAML query specifies that you want to search the Title field (where it says FieldRef Name="Title"), but the GUID you are looking for would not be in that field. The list items I work with have two GUID fields, one named GUID and another named UniqueId. These two fields have different values, so you may need to try both to see which holds the value you want.

For the GUID field, your query should be like this:

string sQuery = @"<Where><Eq><FieldRef Name=""GUID""></FieldRef><Value Type=""Text"">"+guid+"</Value></Eq></Where>";

For the UniqueId field, your query should be like this:

string sQuery = @"<Where><Eq><FieldRef Name=""UniqueId""></FieldRef><Value Type=""Text"">"+guid+"</Value></Eq></Where>";