0

hello I have this code with which I get all the columns of sharepoint list, but now I want to get certain columns in specific how I could do it or can you suggest me how to do it through caml query

Thanks in advance

This is the code

           List list = clientContext.Web.Lists.GetByTitle("Employees");

            clientContext.Load(list);
            clientContext.ExecuteQuery();

            //Getting Column Names
            FieldCollection fieldCollection = list.Fields;
            clientContext.Load(fieldCollection);
            clientContext.ExecuteQuery();

            foreach (Field myField in fieldCollection)
            Console.WriteLine(myField.Title);
            Console.ReadLine();

1 Answer 1

1

CAML query is used to query items based on the field values.

If you want to get the specific field title, you don’t need CAML.

If you want to get the specific field by some conditions:

foreach (Field field in fieldCollection){
    string internalName = field.InternalName;
    string staticName = field.StaticName;
    string displayName = field.Title;
    string fieldType = field.TypeDisplayName;
    // get field based on the internal name of field
    if(internalName == "Title"){
        Console.WriteLine(field.Title);
    }
    // get field based on the static name of field
    if (staticName == "Title")
    {
        Console.WriteLine(field.Title);
    }
    // get field based on the display name of field
    if (displayName == "Title")
    {
        Console.WriteLine(field.Title);
    }
    // get field based on the field type
    if (fieldType == "Single line of text")
    {
        Console.WriteLine(field.Title);
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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