通过CSOM动态加载项目在线属性

时间:2015-10-22 21:23:40

标签: c# sharepoint-2013 csom ms-project-server-2013 project-online

我正在尝试将项目从在线项目加载到.NET应用程序中,而我可以加载项目,我遇到的一件事就是加载我想要的所有列。我知道我可以使用include指定要加载的列,但我希望能够使用可以动态生成的列列表。

它是ETL程序的一部分,我想让用户配置被带入缓存数据库的列列表。以下是我到目前为止的内容

    static void Main(string[] args)
    {
        ProjectContext pc = getProjCtxt();

        pc.Load(pc.Projects);
        pc.ExecuteQuery();
        ColumnNames fldList = new ColumnNames();
        var enumerator = pc.Projects.GetEnumerator();

        while (enumerator.MoveNext()) {
            var p2 = enumerator.Current;
            pc.Load(p2);
            pc.ExecuteQuery();
            Console.WriteLine(p2.FinishDate);
        }

        foreach (PublishedProject p in pc.Projects)
        {
            var pubProj = p.IncludeCustomFields;

            pc.Load(pubProj);

            pc.ExecuteQuery();

            //Dictionary<string, object> projDict = pubProj.FieldValues;
            var type = p.GetType();

            foreach(ColumnNames.colInfo ci in fldList.impFields)
            {
                if (type.GetProperty(ci.FieldName) != null)
                {
                    Console.WriteLine(p.FinishDate);
                    Console.WriteLine(type.GetProperty(ci.FieldName).GetValue(p, null));
                }

            }
         }
     }

我在FinishDate上收到错误,因为它没有初始化我如何初始化任务/项目的所有属性,所以如果程序事先不知道我可以使用它们它正在寻找什么样的列。

有没有办法建立一个字符串并将其传递给在线项目,告诉它要初始化哪些属性。?

1 个答案:

答案 0 :(得分:3)

所以我最终找到了答案。 https://sharepoint.stackexchange.com/questions/89634/syntax-for-including-fields-dynamically-in-csom-query

管理也可以简化vode并进行清理。以及确保我只在显式属性列表中包含非自定义字段,因为IncludeCustomFields选项会将所有自定义字段都包含在内。

$(function() {
  var myOption= $("#mySelect option:selected").val();
 $("#search").attr("placeholder", myOption);  
});
相关问题