SPUser with person and group field
来源:互联网 发布:淘宝儿童卡通墙贴 编辑:程序博客网 时间:2024/06/04 18:09
Use the AllUsers property of theSPWeb class to return all the users of a site. This includes users granted permissions directly, users granted permissions through a group who have then visited the site, and users who have been referenced in a person field, such as being assigned a task. CallingAllUsers[name] will throw an exception if the user is not there.
Use the SiteUsers property of theSPWeb class to return all the users in the site collection.
Use the GetAllAuthenticatedUsers method of theSPUtility class to return all authenticated users of a site.
Use the GetUniqueUsers method of theSPAlertCollection class to return a list of users for a collection of alerts.
Otherwise, use the Users property of theSPGroup orSPWeb class to return the users in a group or site.
Use an indexer to return a single user from the collection. For example, if the collection is assigned to a variable namedcollUsers, usecollUsers[index] in C#, orcollUsers(index) in Visual Basic, whereindex is either the index number of the user in the collection or the user name of the user.
Every user has a unique member ID (ID property), has the permissions associated with that membership, and can be represented by anSPMember object. The following example assigns a user to anSPMember object, given a specified SharePoint Web site:
SPWeb oWebsite = SPContext.Current.Web;SPMember oMember = oWebsite.AllUsers["Domain\\User_Alias"];
SPSite oSiteCollection = SPContext.Current.Site;using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"]){ SPUser oUser = oWebsite.AllUsers["User_Name"];//It is Id oUser.Email = " E-mail_Address"; oUser.Name = " Display_Name"; oUser.Notes = " User_Notes"; oUser.Update();}
Try using the EnsureUser() function of the SPWeb object.SPWeb web = SPContext.Current.Web;SPUser user = web.EnsureUser(@"domain\username");
The following code example uses the SiteUsers property to return the collection of users for the current site collection and the user display names
This example requires using directives (Imports in Microsoft Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.
using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL")){ SPUserCollection collUsers = oWebsite.SiteUsers; foreach (SPUser oUser in collUsers) { Response.Write(SPEncode.HtmlEncode(oUser.Name) + "<BR>"); }}Use the Groups property of the SPUser or SPWeb class to return the collection of groups for the user or Web site. Otherwise, use the OwnedGroups property of the SPUser class to return the collection of groups owned by a user, or the SiteGroups property of the SPWeb class to return all the groups in the site collection.
Use an indexer to return a single group from the collection. For example, if the collection is assigned to a variable named collGroups, use myGroups[index] in Microsoft C#, or myGroups(index) in Microsoft Visual Basic, where index is either the index number of the group in the collection or the name of the group.
Every group can be represented by an SPMember object and has a unique member identifier (see ID property). The following example assigns a group to an SPMember object:
SPMember oMember = oWebsite.SiteGroups["Cross-Site_Group_Name"];For general information about groups and security, see Authorization, users, groups, and the object model in SharePoint 2013.
ExamplesThe following code example changes the name, owner, and description of a group in a site collection.
using (SPWeb oWebsite = SPContext.Current.Site.RootWeb){ SPGroup oGroup = oWebsite.SiteGroups["Original_Name"]; oGroup.Name = "New_Name"; oGroup.Owner = oWebsite.Users["Domain_Name\\User"]; oGroup.Description = "Description"; oGroup.Update();}Using SharePoint object model we can pull out all the cross-site groups either by using SPWeb.Groups or by using SPWeb.SiteGroups. Then what is the difference between the two?
SPWeb.Groups will allow you to pull out only the groups which have some / any kind of permissions defined within the site.
SPWeb.SiteGroups will pull out all the cross-site groups irrespective of any permission defined.
So, the next time you try to pull out the Groups using SPWeb.Groups, you will not get astonished by not finding few of the Groups within the retrieved collection.
Note: The same also applies to the cross-site user collection retrieval using either SPWeb.Users or SPWeb.SiteUsers.
- SPUser with person and group field
- field-group
- aaa using radius, localdb, with group mapping and default group.
- Relation between Data References and Field symbols with examples
- There is no Action mapped for namespace [/] and action name [Person] associated with context path
- Bit-Scalable Deep Hashing with Regularized Similarity Learning for Image Retrieval and Person Re-ide
- Test of MV FAST refresh with Sum and group
- with(field)方法
- canada goose sale online With extra and surplus folk spare not effort apt show their uncommon person
- Understanding blank/null field values for using with all() and none() peoplecode functions
- What's different with Field symbol and Data reference in SAP-ABAP
- Faceting on a field in SolrCloud with docValues=true and indexed=false fails
- 【Person Re-ID】Person Re-identification: Past, Present and Future
- Ada and Field
- SPOJ Ada and Field
- Getting started with XNA - First Person Camera
- oracle listagg(field,',') within group(order by field)
- Field.Text AND Field.Keyword in Lucene
- 最长不下降序列
- GLSL核心课程---聚光灯
- 土耳其旅游记录
- 黑马程序员_Asp.Net防盗链
- C++类成员函数指针和一般函数指针的编译模式的差别
- SPUser with person and group field
- 走进谷歌 -- 去了就不想离开的 Google 总部
- hdu-4587-线段树的区间操作- lazy标记
- 螺丝的参数
- hdu 1421 搬寝室
- c++ 多线程调试小技巧
- Flex FileReference 在Firefox 浏览器情况下的异常情况
- timus 1081. Binary Lexicographic Sequence URAL 解题报告
- eclipse添加logcat显示