2016-07-06 19 views
2

私は簡単な作業をしようとします:Visual Studioの助けを借りて、ベースラインなどのタスクに関する情報を取得しようとします。 すべてのプロジェクトを読み込んで取得できますが、タスクのリストは取得できません。どのように私はそれを得ることができますか?あなたが最初のタスクをロードする必要がC#経由でProject Server 2016と統合

"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.

答えて

0

:私は、エラー、次のしている。その後

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

     } 
    } 
} 

:ここに 私のコードの例

foreach (PublishedProject pubProj in projContext.Projects) 
{ 
    Console.WriteLine("\n\t{0} : {1}", pubProj.Name, pubProj.CreatedDate.ToString()); 
    projContext.Load(pubProj.Tasks); 
    projContext.ExecuteQuery(); 
    foreach (PublishedTask item in pubProj.Tasks) 
    { 
     foreach (PublishedTask pubTask in pubProj.Tasks) 
     { 
     Console.WriteLine("\n{0}", pubTask.Name); 
     } 
    } 
} 
関連する問題