Get value from People Picker
========================================================================================
if (ppereceived.Accounts.Count > 0)
{
SearchValues.ccc = ppereceived.Accounts[0].ToString().Split('|')[1];
}
//SearchValues.sends = ppesend.ResolvedEntities.ToString();
if (ppesend.Accounts.Count > 0)
{
SearchValues.sends = ppesend.Accounts[0].ToString().Split('|')[1];
}
========================================================================================
set value to People Picker
========================================================================================
if (SearchValues.ccc != null)
{
//SearchValues.ccc = SearchValues.ccc.Remove(SearchValues.ccc.Length - 1);
//usercollection = new SPFieldUserValueCollection();
string[] userarray = SearchValues.ccc.Split(',');
// for (int i = 0; i < userarray.Length; i++)
foreach (string tuser in userarray)
{
SPFieldUserValue usertoadd = ConvertLoginName(tuser);
//usercollection.Add(usertoadd);
//ppesend = usertoadd.;
ppereceived.CommaSeparatedAccounts = usertoadd.User.Name;
ppereceived.Validate();
}
}
//usercollection.Add(ppesend);
if (SearchValues.sends != null)
{
//SearchValues.sends = SearchValues.sends.Remove(SearchValues.sends.Length - 1);
//usercollection = new SPFieldUserValueCollection();
string[] userarrays = SearchValues.sends.Split(',');
// for (int i = 0; i < userarray.Length; i++)
foreach (string tusers in userarrays)
{
SPFieldUserValue usertoadds = ConvertLoginName(tusers);
//usercollection.Add(usertoadd);
//ppesend = usertoadd.;
ppesend.CommaSeparatedAccounts = usertoadds.User.Name;
ppesend.Validate();
}
}
=======================================================================================================
public SPFieldUserValue ConvertLoginName(string userid)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSite = new SPSite(guidSiteID))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
oWeb.AllowUnsafeUpdates = true;
SPUser requireduser = oWeb.EnsureUser(userid);
uservalue = new SPFieldUserValue(oWeb, requireduser.ID, requireduser.LoginName);
oWeb.AllowUnsafeUpdates = false;
}
}
});
return uservalue;
}
==========================================================================================================
========================================================================================
if (ppereceived.Accounts.Count > 0)
{
SearchValues.ccc = ppereceived.Accounts[0].ToString().Split('|')[1];
}
//SearchValues.sends = ppesend.ResolvedEntities.ToString();
if (ppesend.Accounts.Count > 0)
{
SearchValues.sends = ppesend.Accounts[0].ToString().Split('|')[1];
}
========================================================================================
set value to People Picker
========================================================================================
if (SearchValues.ccc != null)
{
//SearchValues.ccc = SearchValues.ccc.Remove(SearchValues.ccc.Length - 1);
//usercollection = new SPFieldUserValueCollection();
string[] userarray = SearchValues.ccc.Split(',');
// for (int i = 0; i < userarray.Length; i++)
foreach (string tuser in userarray)
{
SPFieldUserValue usertoadd = ConvertLoginName(tuser);
//usercollection.Add(usertoadd);
//ppesend = usertoadd.;
ppereceived.CommaSeparatedAccounts = usertoadd.User.Name;
ppereceived.Validate();
}
}
//usercollection.Add(ppesend);
if (SearchValues.sends != null)
{
//SearchValues.sends = SearchValues.sends.Remove(SearchValues.sends.Length - 1);
//usercollection = new SPFieldUserValueCollection();
string[] userarrays = SearchValues.sends.Split(',');
// for (int i = 0; i < userarray.Length; i++)
foreach (string tusers in userarrays)
{
SPFieldUserValue usertoadds = ConvertLoginName(tusers);
//usercollection.Add(usertoadd);
//ppesend = usertoadd.;
ppesend.CommaSeparatedAccounts = usertoadds.User.Name;
ppesend.Validate();
}
}
=======================================================================================================
public SPFieldUserValue ConvertLoginName(string userid)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSite = new SPSite(guidSiteID))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
oWeb.AllowUnsafeUpdates = true;
SPUser requireduser = oWeb.EnsureUser(userid);
uservalue = new SPFieldUserValue(oWeb, requireduser.ID, requireduser.LoginName);
oWeb.AllowUnsafeUpdates = false;
}
}
});
return uservalue;
}
==========================================================================================================
No comments:
Post a Comment