Share via


SPUser class

代表在Microsoft SharePoint Foundation中的使用者。

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.SPMember
    Microsoft.SharePoint.SPPrincipal
      Microsoft.SharePoint.SPUser

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public NotInheritable Class SPUser _
    Inherits SPPrincipal
'用途
Dim instance As SPUser
public sealed class SPUser : SPPrincipal

備註

您可以使用SPWeb類別的AllUsers屬性,傳回的站台的所有使用者。這包括直接授與權限的使用者,授與使用者群組,然後瀏覽過網站,並已將其參考的人欄位中,例如被指派工作的使用者權限。呼叫AllUsers[name]將會擲回例外狀況如果使用者不存在。

若要在網站集合中傳回的所有使用者使用SPWeb類別的 [ SiteUsers ] 屬性。

您可以使用SPUtility類別的GetAllAuthenticatedUsers方法,傳回站台的所有已驗證的使用者。

使用SPAlertCollection類別的GetUniqueUsers方法,傳回集合的警示的使用者清單。

否則,請使用SPGroupSPWeb類別的Users屬性來傳回使用者在 [群組或站台。

若要從集合傳回單一使用者使用索引子。例如,如果集合指派給一個名為collUsers變數中,使用在 C# 的collUsers[index]或 Visual Basic,其中index是使用者在集合中的索引編號,或者是使用者的使用者名稱中的collUsers(index) 。

每一位使用者有唯一的成員 ID (ID屬性)、 具有成員資格,相關聯的權限,而且可以由SPMember物件。下列範例會將使用者指派給SPMember物件,提供指定的 SharePoint 網站:

Dim oWebsite As SPWeb = SPContext.Current.Web
Dim oMember As SPMember = oWebsite.AllUsers("Domain\\User_Alias")
SPWeb oWebsite = SPContext.Current.Web;
SPMember oMember = oWebsite.AllUsers["Domain\\User_Alias"];

一般使用者和安全性的詳細資訊,請參閱Security, Users, and Groups in Windows SharePoint Services

Examples

下列程式碼範例會修改電子郵件地址、 顯示名稱和指定的使用者物件的備忘稿。

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim user As SPUser = site.AllUsers("User_Name")

user.Email = "E-mail_Address"
user.Name = "Display_Name"
user.Notes = "User_Notes"

user.Update()
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPUser oUser = oWebsite.AllUsers["User_Name"];

    oUser.Email = " E-mail_Address";
    oUser.Name = " Display_Name";
    oUser.Notes = " User_Notes";

    oUser.Update();
}
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

請參閱

參照

SPUser members

Microsoft.SharePoint namespace