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 have a list with 3 views.

I want find special items of this. I use SPQuery for it.

<Where>
 <Eq>
   <FieldRef Name='TypeTitle' />
   <Value Type='Lookup'>Test1</Value>
 </Eq>
</Where>

and getitems of list :

string viewname="View1";
list.GetItems(query,viewname).GetDataTable();

But return all items of view allitems with name :Test1. While the there is no item to View1 .

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

If you have a look at the definition of the SPList.GetItems(SPQuery,string) method: http://msdn.microsoft.com/en-us/library/ms434064.aspx

You can see that the second parameter needs to be the GUID of the view enclosed in curly braces. Eg: {B080E5D2-DEF9-11E1-8A8D-550A6188709B}

Try the following code:

string viewGUID = list.Views["View1"].ID.ToString("B").ToUpper();
list.GetItems(query,viewGUID).GetDataTable();

Also, in the MSDN docs it is stated that:

The properties of the view that is specified by the viewName parameter override the properties that are specified in the query object that is passed through the query parameter. For example, if the query object includes a tag that specifies only items containing a particular column value, while the view specifies to return all items, this method retrieves all of the items

share|improve this answer
    
Thanks a lot :) –  ar.gorgin Aug 6 '12 at 4:41
add comment

Your Answer

 
discard

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

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