![](/img/trans.png)
[英]SharePoint Online - Update User Profile Properties via CSOM App
[英]Dynamically Loading Project Online Properties via CSOM
我正在嘗試將我們的項目從項目在線加載到.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上得到一個錯誤,因為它尚未初始化如何初始化任務/項目的所有屬性,所以如果程序不提前知道它正在尋找什么列,我可以使用它們。
有沒有辦法建立一個字符串並將其傳遞給在線項目,告訴它要初始化什么屬性。
所以我最終找到了答案。 https://sharepoint.stackexchange.com/questions/89634/syntax-for-including-fields-dynamically-in-csom-query
管理也可以簡化vode並清理它。 以及確保我只在顯式屬性列表中包含非自定義字段,因為IncludeCustomFields選項將所有自定義字段都包含在內。
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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.