gpt4 book ai didi

c# - 以编程方式将用户添加到列表

转载 作者:太空宇宙 更新时间:2023-11-03 14:25:40 25 4
gpt4 key购买 nike


我有一个列表,该列表是从接受用户输入的程序中填充的,在将个人或组添加到列表中的其中一列时遇到问题。有人知道怎么做吗?

最佳答案

看看这篇文章:http://blogs.msdn.com/b/uksharepoint/archive/2009/02/17/quick-tip-using-the-sharepoint-person-or-group-field-in-code-part-1.aspx

它向您展示了如何使用它:

Console.WriteLine("Enter a ; delimited list of domain\alias that need to be added:");
string sAliases = Console.ReadLine(); //captures whatever the user entered
string sValueToAddToFieldInSP = ""; //used to build the full string needed for the person field

string sAllContacts = "";

using (SPSite site = new SPSite(“http://sites/site/yoursite”))
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.RootWeb)
{
web.AllowUnsafeUpdates = true;
string[] aAliases = sAliases.Split(';');
foreach (string sAlias in aAliases)
{
SPUser user = web.EnsureUser(sAlias);
sAllContacts += user.ID.ToString() + ";#" + user.LoginName.ToString() + ";#";
}
web.Update();
}
}

if (sAllContacts.EndsWith(";#"))
{
sAllContacts = sAllContacts.Substring(0, sAllContacts.Length - 2);
}

//add the list item
SPList l = web.Lists["<name of your list>"];
SPListItem li= l.Items.Add();
li["Title"] = sAllContacts ;
li["MyPerson"] = sAllContacts ;
li.Update();
Console.WriteLine("Done");

关于c# - 以编程方式将用户添加到列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4124297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com