Design Code:-
<table>
<tr>
<td>
<SharePoint:PeopleEditor ID="PplMultiapp" runat="server" Width="250px" Height="25px" MultiSelect="true"/>
</td>
<td>
<asp:Button ID="BtnMutiuser" runat="server" Text="AddMultiuser" OnClick="BtnMutiuser_Click" />
</td>
</tr>
</table>
Cs Code:-
SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
SPSite oSPsite = new SPSite(SPContext.Current.Site.ID);
SPWeb oSPWeb = oSPsite.OpenWeb();
SPList list = oSPWeb.Lists["PeopleList"];
oSPWeb.AllowUnsafeUpdates = true;
int iPeople = PplMultiapp.ResolvedEntities.Count;
SPListItem oSPListItem = list.Items.Add();
string[] UsersSeperated = PplMultiapp.CommaSeparatedAccounts.Split(',');
foreach (string UserSeperated in UsersSeperated)
{
SPUser User = oSPWeb.SiteUsers[UserSeperated];
SPFieldUserValue UserName = new SPFieldUserValue(oSPWeb, User.ID, User.LoginName);
UserCollection.Add(UserName);
}
oSPListItem["Title"] = "Test Title";
oSPListItem["user1"] = UserCollection;
oSPListItem.Update();
<table>
<tr>
<td>
<SharePoint:PeopleEditor ID="PplMultiapp" runat="server" Width="250px" Height="25px" MultiSelect="true"/>
</td>
<td>
<asp:Button ID="BtnMutiuser" runat="server" Text="AddMultiuser" OnClick="BtnMutiuser_Click" />
</td>
</tr>
</table>
Cs Code:-
SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
SPSite oSPsite = new SPSite(SPContext.Current.Site.ID);
SPWeb oSPWeb = oSPsite.OpenWeb();
SPList list = oSPWeb.Lists["PeopleList"];
oSPWeb.AllowUnsafeUpdates = true;
int iPeople = PplMultiapp.ResolvedEntities.Count;
SPListItem oSPListItem = list.Items.Add();
string[] UsersSeperated = PplMultiapp.CommaSeparatedAccounts.Split(',');
foreach (string UserSeperated in UsersSeperated)
{
SPUser User = oSPWeb.SiteUsers[UserSeperated];
SPFieldUserValue UserName = new SPFieldUserValue(oSPWeb, User.ID, User.LoginName);
UserCollection.Add(UserName);
}
oSPListItem["Title"] = "Test Title";
oSPListItem["user1"] = UserCollection;
oSPListItem.Update();
No comments:
Post a Comment