ServerContext 类 (Microsoft.Office.Server)

Provides run-time methods for shared services in Microsoft Office SharePoint Server 2007.

命名空间: Microsoft.Office.Server
程序集: Microsoft.Office.Server (在 microsoft.office.server.dll 中)

语法

声明
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
Public NotInheritable Class ServerContext
用法
Dim instance As ServerContext
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
public sealed class ServerContext

示例

//Updates a user profile
//Creates a user profile. Obtains the property values from the default 
//domain controller or the master connection that is configured on the 
//server
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using System.Web;

namespace UserProfilesApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (SPSite site = new SPSite("https://servername"))
                {
                    ServerContext context = ServerContext.GetContext(site);
                    UserProfileManager profileManager = new UserProfileManager(context);
                    string sAccount = "domainname\\username";
                    UserProfile u = profileManager.GetUserProfile(sAccount);
                    u[PropertyConstants.HomePhone].Value = "nnnnnnnnnn";
                    u[PropertyConstants.CellPhone].Value = "nnnnnnnnnn";
                    u.Commit();
                }
            }
            catch (UserNotFoundException exception)
            {
                Console.WriteLine(exception.ToString());
            }
        }
    }
}

继承层次结构

System.Object
  Microsoft.Office.Server.ServerContext

线程安全性

此类型的任何公共静态( Visual Basic 中共享)成员是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

参考

ServerContext 成员
Microsoft.Office.Server 命名空间