I try to do a simple task: with help of Visual Studio I try to get info about tasks such as baseline. I can read and get all projects, but can't get list of tasks. How I can get it? Here the example of my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ProjectServer.Client;
namespace ProjectAPI
{
class Program1
{
private const string pwaPath = "https://XXXXXXXXX";
private static string projName = string.Empty;
private static ProjectContext projContext;
private static PublishedTask projTasks;
static void Main(string[] args)
{
projContext = new ProjectContext(pwaPath);
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
List<string> TasksID = new List<string>();
foreach (PublishedProject pubProj in projContext.Projects)
{
Console.WriteLine("\n\t{0} : {1}", pubProj.Name, pubProj.CreatedDate.ToString());
foreach (PublishedTask item in pubProj.Tasks)
{
TasksID.Add(projTasks.Name);
}
Console.WriteLine("\nProject ID : Project name : Created date");
}
Console.Write("\nPress any key to exit: ");
Console.ReadKey(false);
}
}
}
After that i have following error:
"Microsoft.SharePoint.Client.CollectionNotInitializedException" in Microsoft.SharePoint.Client.Runtime.dll
The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.