CAML Query for get only View Fields not all List Items in SharePoint List

//Get SharePoint List from SharePoint Site
SPList listEmp = currentWeb.Lists["Employee_Master"];

//Create SharePoint Query Object for use CAML Query
SPQuery qryEmp = new SPQuery();

//CAML Query to Get SharePoint List Records SharePoint List ( SPQuery object & CAML)

qryEmp.Query = “” + Name + “”;

//Select what are the fields you want to retrieve from CAML Query.(Not all Columns from SharePoint List)

qryEmp.ViewFields = string.Concat(
“<FieldRef Name=’Employee_ID’ />”,
“<FieldRef Name=’First_Name’ />”,
“<FieldRef Name=’Email’ />”,
“<FieldRef Name=’Login_ID’ />”,
“<FieldRef Name=’Immidiate_Supervisor’ />”,
“<FieldRef Name=’Department’ />”);

qryEmp.ViewFieldsOnly = true;

//Assign result data set (which are get from CAML Query with View Fields) to SPListItem Collection

SPListItemCollection itemCollectionEmp = listEmp.GetItems(qryEmp);


Author: eshan1604

Hi Guys, I'm Udara Eshan Ariyarathne from Sri Lanka. Currently i'm working as a Software Engineer (Microsoft Technologies). I'm sharing some IT related articles such as Development ,Configuration and Designing things what i have learn from day to day works. Hope it useful all of us. "Enjoying IT" Thanks & Regards, Udara Eshan Ariyarthne

One thought on “CAML Query for get only View Fields not all List Items in SharePoint List”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s