I am having trouble aggregating info on all tasks from current user programmatically. This is what I got so far:
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists ServerTemplate=\"107\" />";
query.Webs = "<Webs Scope=\"SiteCollection\" />";
query.ViewFields = "<FieldRef Name=\"Title\"/>" + "<FieldRef Name=\"AssignedTo\" />" + "<FieldRef Name=\"Status\" />";
DataTable results = web.GetSiteData(query);
This gets me all tasks from Tasks lists across the entire site collection which I can later filter. However it will not count the tasks that the user assigned to himself in his MySite for example.
Here is how I tried to get all the tasks from the user's MySite:
using (SPSite site = new SPSite("http://myhostname:8080/personal/username/"))
{
using (SPWeb mySiteWeb = site.OpenWeb())
{
SPList list = mySiteWeb.Lists["WmaAggregatorList_User"];
foreach (SPListItem listItem in list.Items)
{
this.Controls.Add(new LiteralControl("<br>" + listItem.Title + "(" + listItem.DisplayName + ") - " + listItem.ContentTypeId + "<br>"));
}
}
}
This works to a degree - It gives me a lot of empty fields and fields that are definitely not tasks:
((no title)) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 ((no title)) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 SPTaskListProvider(SPTaskListProvider) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 ((no title)) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 My Machine Name(My Machine Name) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 My Machine Name: Tasks(My Machine Name: Tasks) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 ((no title)) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 First Task(First Task) - 0x001CF7603F6B21D44FB39AE4F99715DEA7 Second Task(Second Task) - 0x001CF7603F6B21D44FB39AE4F99715DEA7
Only the last two are actually users' tasks. Would anybody have an idea of a good way to extract user's tasks from his mysite and filter out the unneeded data?