I'am using SPSitedataquery to query to 7 task lists but in all i have 8 task lists but i want to exclude 1 task list from the query how can i do it? Any ideas? Thanks in advance? Following is my code

 SPSiteDataQuery oQuery = new SPSiteDataQuery();
                oQuery.Lists = "<Lists ServerTemplate=\"171\" />";
                oQuery.Query = string.Concat("<Where>",
                                        "<FieldRef Name='Status'/>",
                                        "<Value Type='Choice'>Completed</Value>",
                                        "<FieldRef Name='ReminderDate' />",
                                        "<Value Type='Calculated'><Today /></Value>",
                oQuery.ViewFields = "<FieldRef Name=\"Title\" />" +  /* Title is LastName column </Today>2014-03-29T00:00:00Z*/
                  "<FieldRef Name=\"StartDate\"/>" +
                   "<FieldRef Name=\"DueDate\"/>" +
                   "<FieldRef Name=\"Body\"/>" +
                   "<FieldRef Name=\"NewJoiner\"/>" +
                   "<FieldRef Name=\"AssignedTo\"/>" +
                   "<ListProperty Name=\"Title\"/>";
                oQuery.Webs = "<Webs Scope=\"Recursive\" />";//Recursive
                DataTable dtTasks = oWeb.GetSiteData(oQuery);

I want something wherein i can query to all remaining 7 task lists except 1 task list.


You could specify in Query which items to exclude from results.

For example, the following query:

<Neq><FieldRef Name='FileDirRef' /><Value Type='Lookup'>/project/Lists/Tasks</Value></Neq>

will exclude all task items from Tasks list located on Project site.

| improve this answer | |

You can not do that in the query, if you want to use SPSiteDataQuery you will have to do this filtering on the returned objects

| improve this answer | |

When a template is specified, the data is returned from all lists of that type and as mentioned by @Robert, you will then need to filter the returned object. However, there is other way in which you can specify the IDs of the lists instead of template. Example:

  <List ID="7A9FDBE6-0841-430a-8D9A-53355801B5D5" />
  <List ID="3D18F506-FCA1-451e-B645-2D720DC84FD8" />

So, what you can do: first find all the lists with specific template and generate the Lists node for the SPSitedataquery. In this you can exclude/include the lists you want.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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