SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list with 3 views.

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

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

and getitems of list :

string viewname="View1";

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

share|improve this question
up vote 1 down vote accepted

If you have a look at the definition of the SPList.GetItems(SPQuery,string) method:

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();

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

Your Answer


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.