通过C#与Project Server 2016集成

时间:2016-07-06 14:45:01

标签: c# integration project-server ms-project-server-2013

我尝试做一个简单的任务:在Visual Studio的帮助下,我尝试获取有关诸如基线之类的任务的信息。 我可以阅读并获取所有项目,但无法获得任务列表。我怎么能得到它? 这是我的代码示例:

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

        }
    }
}

之后我有以下错误:

  

&#34; Microsoft.SharePoint.Client.CollectionNotInitializedException&#34;在   Microsoft.SharePoint.Client.Runtime.dll

     

该集合尚未初始化。它   未被请求或请求尚未执行。有可能   需要明确要求。

1 个答案:

答案 0 :(得分:0)

您需要先加载任务:

private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
    ((sender as FrameworkElement).DataContext as InnerClass)?.targetFun();
}