Look at the picture below. Do you want to get rid of this button icon when you add it as webpart or view?
It is pretty easy. Just edit its webpart, then in List Views Section, choose No Toolbar.
Thursday, August 16, 2012
Set value to SharePoint:PeopleEditor
Set value to SharePoint:PeopleEditor using c# code in visual studio 2010.
Ex.
txbTravelers.CommaSeparatedAccounts = SPContext.Current.Web.CurrentUser.LoginName;
Ex.
txbTravelers.CommaSeparatedAccounts = SPContext.Current.Web.CurrentUser.LoginName;
Sharepoint: Get Current Login User
Get Current Login User using c# in Sharepoint
Ex.
var currentUser = SPContext.Current.Web.CurrentUser.LoginName;
Ex.
var currentUser = SPContext.Current.Web.CurrentUser.LoginName;
Get SPFieldUserValueCollection value from ListItem in SharePoint
This is a way to get user from person/group field in sharepoint.
var item = workflowProperties.Item["Approvers"];
var users = (SPFieldUserValueCollection)workflowProperties.List.Fields["Approvers"].GetFieldValue(item.ToString());
var item = workflowProperties.Item["Approvers"];
var users = (SPFieldUserValueCollection)workflowProperties.List.Fields["Approvers"].GetFieldValue(item.ToString());
Get value SPFieldUserValueCollection in Sharepoint
Get value from Sharepoint:PeopleEditor and save to list.
Linq expression
var thisWeb = SPContext.Current.Web;
var list = thisWeb.Lists["List name"];
var listItems = list.Items;
var item = listItems.Add();
var usersstring = txbTravelers.Accounts;
var usersfield = new SPFieldUserValueCollection();
usersfield.AddRange(from object s in usersstring select thisWeb.SiteUsers[s.ToString()] into user select new SPFieldUserValue(thisWeb, user.ID, user.LoginName));
item[new Guid("fb51591c-e3d2-401f-9e33-f012c2ff88fa")] = usersfield;
item.Update();
C# code
var usersstring = txbTravelers.Accounts;
var usersfield = new SPFieldUserValueCollection();
foreach (var s in usersstring)
{
var user = thisWeb.SiteUsers[s.ToString()];
usersfield.Add(new SPFieldUserValue(thisWeb,user.ID,user.LoginName));
}
Linq expression
var thisWeb = SPContext.Current.Web;
var list = thisWeb.Lists["List name"];
var listItems = list.Items;
var item = listItems.Add();
var usersstring = txbTravelers.Accounts;
var usersfield = new SPFieldUserValueCollection();
usersfield.AddRange(from object s in usersstring select thisWeb.SiteUsers[s.ToString()] into user select new SPFieldUserValue(thisWeb, user.ID, user.LoginName));
item[new Guid("fb51591c-e3d2-401f-9e33-f012c2ff88fa")] = usersfield;
item.Update();
C# code
var usersstring = txbTravelers.Accounts;
var usersfield = new SPFieldUserValueCollection();
foreach (var s in usersstring)
{
var user = thisWeb.SiteUsers[s.ToString()];
usersfield.Add(new SPFieldUserValue(thisWeb,user.ID,user.LoginName));
}
Subscribe to:
Posts (Atom)