简体   繁体   English

如何在Project Server 2013(C#VSTO加载项)中更改自定义字段的值

[英]How to change the value of a custom field in Project Server 2013 (C# VSTO AddIn)

I am trying to update/change an enterprise custom field of a project from within a MS project plugin written in C#. 我正在尝试从用C#编写的MS项目插件中更新/更改项目的企业自定义字段。 I found information on how to update an enterprise custom field on task or resource level: 我找到了有关如何在任务或资源级别上更新企业自定义字段的信息:

MSProject.Task t = ....;
t.SetField(Application.FieldNameToFieldConstant("xyz"),"value");

But I simply cannot find any documentation or examples of how to do that for a custom field on the project level. 但是我根本找不到在项目级别的自定义字段的任何文档或示例。

Maybe I am just using the wrong search phrases. 也许我只是使用了错误的搜索短语。 I tried to google different key words like project header field and similar words as well, but found nothing. 我试图用谷歌搜索不同的关键词,例如项目标题字段和类似的关键词,但是什么也没找到。

I am inclined to think that maybe it is not possible? 我倾向于认为也许不可能吗?

After hours of searching I finally found the solution. 经过数小时的搜索,我终于找到了解决方案。 It is actually really simple once you know how it is done. 一旦知道如何完成,它实际上真的很简单。

The project has a summary task which has all the custom fields of the project. 该项目有一个摘要任务,其中包含该项目的所有自定义字段。

MSProject.Project proj = ...;
var field = proj.Application.FieldNameToFieldConstant("field_name", MSProject.PjFieldType.pjProject);
proj.ProjectSummaryTask.SetField(field, "value");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM