Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using SPQuery to fetch data (particular columns from the list based on viewID) from SharePoint list. Here is the code for fetching the data:

SPQuery sQuery = new SPQuery();
currentlistview = splist.GetView(new Guid(listViewID));
foreach (string viewField in currentlistview.ViewFields)
{
  SPField spfield = splist.Fields.GetField(viewField);
  SPListColumnValues.Add(spfield);
  sQuery.ViewFields += "<FieldRef Name='" + viewField + "' />";
}
sQuery.ViewAttributes = "Scope=\"Recursive\"";
sQuery.ViewFieldsOnly = true;
DataTable dt =  splist.GetItems(sQuery).GetDataTable()

But I am getting all the columns from the SharePoint list. Could you provide a solution for this issue ?

share|improve this question
    
Are you looking to get the same results from a view into your datatable? You can send the GetItems the SPView object to do so. –  David Lozzi Nov 30 '11 at 14:58
    
Did you check whether currentlistview.ViewFields is actually returning all the fields in the list? –  Kit Menke Nov 30 '11 at 15:50
    
kit Menke : I have checked the currentlistview.ViewFields returns only the particular columns(not all the columns) in the list. So what am I doing wrong ? Could you help me to solve this issue ? –  Ramalingam Dec 1 '11 at 5:47
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.