0

hello I'm doing a query caml in asp.net c # to search by user of my column "users" that I have but only works with a single user, and when I change user and enter another brings me all the users I have and not the that I introduced in specific please help me I have my colsulta wrong? What I want is for me to filter by the user who enters

This is my query

This is my column Users

0

Single User Text field should use Eq condition:

            Microsoft.SharePoint.Client.List spList = ctx.Web.Lists.GetByTitle("Empleados");
            ctx.Load(spList);
            ctx.ExecuteQuery();

            if (spList != null && spList.ItemCount > 0)
            {
                Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml =
                   @"<View>  
                            <Query> 
                               <Where><Eq><FieldRef Name='Usuario' /><Value Type='Text'>jerry@testlz.onmicrosoft.com</Value></Eq></Where> 
                            </Query> 
                            <RowLimt>100</RowLimit>
                      </View>";

                ListItemCollection listItems = spList.GetItems(camlQuery);
                ctx.Load(listItems);
                ctx.ExecuteQuery();
                foreach (ListItem item in listItems)
                {
                    Console.WriteLine(item["Usuario"]);
                }

For multiple user text, use Or, And Condition, here is a sample code for your reference with Or:

    Microsoft.SharePoint.Client.List spList = ctx.Web.Lists.GetByTitle("Empleados");
    ctx.Load(spList);
    ctx.ExecuteQuery();

    if (spList != null && spList.ItemCount > 0)
    {
        Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml =
           @"<View>  
                    <Query> 
                       <Where><Or><Eq><FieldRef Name='Usuario' /><Value Type='Text'>xxx@xxx.onmicrosoft.com</Value></Eq><Eq><FieldRef Name='Usuario' /><Value Type='Text'>xxx@xxx.onmicrosoft.com</Value></Eq></Or></Where> 
                    </Query> 
                    <RowLimt>100</RowLimit>
              </View>";

        ListItemCollection listItems = spList.GetItems(camlQuery);
        ctx.Load(listItems);
        ctx.ExecuteQuery();
        foreach (ListItem item in listItems)
        {
            Console.WriteLine(item["Usuario"]);
        }
    }

Reference about condition of Caml Query:

CAML Query with Multiple Conditions

0

You have "greater or equal to". You probably want "equal to" or other comparison.

  • thank you very much friends I will try your solutions immediately – Abel Avila Sep 18 '18 at 15:34
0

Assuming your Users column is of type string, you can use below query.

For Single User

CamlQuery camlQuery = new CamlQuery(); 
string camqueryStr = "<View><Query><Where><Eq><FieldRef Name='Usuario'/>" + "<Value Type='Text'>" + <**youruseremailladdress**> +  "</Value></Eq></Where></Query><RowLimit>100</RowLimit></View>"; 

For multiple User with OR condition, you might need to loop through and create dynamic query.

List<string> users= new List<string>(); // assuming contains users email address, populate this list with users email address
string camlquery = "<View><Query><Where>";

// Make sure to update column name as per your list
camlquery += "<In><FieldRef Name='Usuario' />"; 
camlquery += "<Values>";

foreach (var user in users)
{
    camlquery += "<Value Type='Text'>" + user + "</Value>";
}

camlquery += "</Values></In></Where></Query></View>";

Hope this helps, happy coding...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.