我是 SharePoint 新手,所以请耐心等待。
我需要能够使用客户端对象模型在我们的自定义列表中创建一个新的列表项。我一直在关注 MSDN 网站 上描述的示例,并且大多数情况下这已经奏效了。
我们有一个包含多个字段的列表,其中包括 UserMulti 字段类型。我在将用户添加到该字段时遇到问题。到目前为止,我已经尝试了以下操作,但这似乎总是默认为系统帐户而不是字段中指定的用户。
...
listItem["ProjectMembers"] = "1;#domain\\johndoe";
listItem.Update();
_clientContext.ExecuteQuery();
我需要先进行某种类型的查找吗?任何帮助表示赞赏。谢谢。
I'm bit of a SharePoint noobie so please bear with me.
I need to be able to create a new list item in one our custom list using the client object model. I have been following the example described on the MSDN site and for the most part this has worked.
We have a list that contains several fields including a UserMulti field type. I am having problems adding users to this field. So far I have tried the following but this somehow always seems to default to the system account rather than the user specified in the field.
...
listItem["ProjectMembers"] = "1;#domain\\johndoe";
listItem.Update();
_clientContext.ExecuteQuery();
Do I need to do some type of lookup first? Any help is appreciated. Thanks.
发布评论
评论(2)
我花了一点时间,但最终我想通了。以下是您可以采取的两种方法
为列表项分配委托人
如果您需要为字段分配多个用户,请分配 FieldUserValue 列表。
我确信有更好的方法来做事,您可以将两者结合起来以确保用户在将其添加到列表之前是有效的,但到目前为止这是有效的。希望这对其他人有帮助。
It took a little while but I figured it out in the end. Below are two approaches you can take
Assign a Principal to the list item
Assign an list of FieldUserValue if you need to assign more than one user to the field.
I'm sure there's better ways of doing things and you could combine the two to ensure that the users are valid before adding them to the list, but this is working so far. Hope this help someone else.
Microsoft 有一篇 wiki 文章“SharePoint:使用 C# 获取和设置字段的完整指南”可以提供帮助。 http://social.technet.microsoft.com/wiki/contents/articles/21801.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-c.aspx# Set_and_Get_a_Multi-Person_Field
它包含此示例代码。
Microsoft has a wiki article, "SharePoint: A Complete Guide to Getting and Setting Fields using C#" that can help. http://social.technet.microsoft.com/wiki/contents/articles/21801.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-c.aspx#Set_and_Get_a_Multi-Person_Field
It includes this sample code.