Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

CAML Query for My Tasks

  Asked By: Nichole    Date: May 04    Category: Sharepoint    Views: 2419

I know that this is not the answer to your real question but anyhow!

I saw that you mention looping through the sites. That is not necesarry with
SPSiteDataQuery. The SPSiteDataQuery has a property "Webs".

Set this like:
mySiteDataQuery.Webs = "<Webs Scope='SiteCollection' />
Then your query will execute on the whole sitecollection. But maybe you know
that allready.

From the SDK:
"Possible values of the Scope attribute include Recursive and SiteCollection.
When the Scope attribute is set to Recursive, the query considers all Web sites
that are descended from the current SPWeb object. For example: <Webs
Scope="Recursive" /> When the Scope attribute is set to SiteCollection, the
query considers all Web sites that are in the same site collection as the
current Web site."

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Kalpana Ghatge     Answered On: May 04

This is also from the SDK, some attributes must be changed because this sample
is for a DocumentLibrary.
Change 101 to 107, 107 is the task list id.


SPWeb site = SPContext.Current.Web;
SPSiteDataQuery query  = new SPSiteDataQuery();
string strWhere =
"<Where>" +
"<Gt>" +
"<FieldRef Name=\"ID\" />" +
"<Value Type=\"Number\">1</Value>" +
"</Gt>" +
"</Where>";
string strOrderBy = "<OrderBy><FieldRef Name=\"FileRef\" /></OrderBy>";
query.Query = strWhere + strOrderBy;
query.Lists = "<Lists ServerTemplate=\"101\" />";
query.ViewFields = "<FieldRef Name=\"Title\" />";

// This is added by me
query.Webs = "<Webs Scope=\"SiteCollection\" />";

DataTable dtResults = site.GetSiteData(query);


Maybe you allready know this but anyhow. Hope it gets you in the right
direction.

 
Answer #2    Answered By: Bobbie Rodgers     Answered On: May 04

If you use the following tool and hook it up to your site
and the task list you will see all the names of all the fields and can
create quite complex CAML syntax. This can then be simply copied into your
code.

http://www.u2u.info/SharePoint/U2U%20Community%20Tools/U2U%20CAML%20Query%20
Builder%202007%20RTM.zip

Once you have the syntax you can then use the following tool to generate
your C# code.

www.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com/ct.ashx?id=543f66bb-ab5f-4a24-b619-" target="_blank" rel="nofollow">www.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com/ct.ashx?id=543f66bb-ab5f-4a24-b619-" target="_blank" rel="nofollow">www.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com/ct.ashx?id=543f66bb-ab5f-4a24-b619-

f8513f946537
<www.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com/ct.ashx?id=543f66bb-ab5f-4a24-b619-" target="_blank" rel="nofollow">www.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com/ct.ashx?id=543f66bb-ab5f-4a24-b619-" target="_blank" rel="nofollow">www.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com/ct.ashx?id=543f66bb-ab5f-4a24-b619-

f8513f946537&url=h
ttp%3a%2f%2fwww.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com%2fcontent%2fbinary%2fYACAMLQT.zip>

&url=http%3a%2f%2fwww.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com%2fcontent%2fbinary%2fYACAMLQT.zip

You can read about this tool here:
http://www.ideseg.com" target="_blank" rel="nofollow">www.ideseg.com/SharePointYetAnotherCAMLQueryTool2.aspx

 
Didn't find what you were looking for? Find more on CAML Query for My Tasks Or get search suggestion and latest updates.




Tagged: