通过CSOM动态加载项目在线属性 [英] Dynamically Loading Project Online Properties via CSOM

查看:115
本文介绍了通过CSOM动态加载项目在线属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking at trying to load our projects from project online into a .NET application, while i can load the projects one thing i'm having trouble with is loading all the columns i would like. I know i can specify the columns i want to load using include but i wanted to be able to use a list of columns that could be generated dynamically.

这是ETL程序的一部分,我希望允许用户配置要带入缓存数据库的列的列表.以下是我到目前为止的情况

It's part of an ETL program that I would like to allow the users to configure the list of columns being brought over into the cache database. Below is what I have so far

    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上收到一个错误,因为它没有很好地初始化,如何初始化任务/项目的所有属性,以便如果程序不提前知道它是什么列,则可以与它们一起使用寻找.

I get an error on the FinishDate because it hasn't been initialized well how to i initialize all the properties of a task/project so i can work with them if the program doesn't know ahead of time what columns it is looking for.

是否可以构建一个字符串并将其在线传递给项目以告诉其要初始化的属性??

Is there a way to build up a string and pass it to the project online to tell it what properties to initialize.?

推荐答案

所以我最终找到了答案. https://sharepoint.stackexchange.com/questions/89634/在csom查询中动态包含字段的语法

So i found an answer buried eventually. https://sharepoint.stackexchange.com/questions/89634/syntax-for-including-fields-dynamically-in-csom-query

还设法简化了视频并清理了视频.并确保我只将非自定义字段包括在显式属性列表中,因为IncludeCustomFields选项使所有自定义字段都随之降低.

Managed to also simplify the vode and clean it up. as well as make sure that i'm only including the non Custom Fields in the explicit properties list since the IncludeCustomFields option brings all the custom fields down with it.

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

        var q = from ColumnNames.colInfo fld in fldList.impFields
                where fld.CustomField == false
                select fld;

        Console.WriteLine(q.Count());

        foreach(ColumnNames.colInfo dynField in q){
            pc.Load(pc.Projects, p => p.Include(pj => pj[dynField.FieldName]));
        }
        pc.Load(pc.Projects, p => p.Include(pj => pj.IncludeCustomFields));
        pc.ExecuteQuery();
    }

这篇关于通过CSOM动态加载项目在线属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆