using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
try
{
using (SPSite site = new SPSite("http://mossweb:1111/sites/Publish"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile user1 = profileManager.GetUserProfile(@"eoffice\user1");
Console.WriteLine("Profile {0}", user1.MultiloginAccounts[0]);
foreach (Property prop in profileManager.Properties)
{
Console.WriteLine("\t{0} : {1}", prop.DisplayName, RenderProperty(user1, prop));
}
Console.ReadLine();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
static string RenderProperty(UserProfile profile, Property prop)
{
UserProfileValueCollection values = profile[prop.Name];
if (values.Value == null)
return "(NULL)";
if (prop.IsMultivalued)
{
StringBuilder sb = new StringBuilder();
foreach (object o in values)
{
sb.AppendFormat("{0} ", o);
}
return sb.ToString();
}
else
{
return values.ToString();
}
}
}
} |
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
try
{
using (SPSite site = new SPSite("http://mossweb:1111/sites/Publish"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile user1 = profileManager.GetUserProfile(@"eoffice\user1");
Console.WriteLine("Profile {0}", user1.MultiloginAccounts[0]);
foreach (Property prop in profileManager.Properties)
{
Console.WriteLine("\t{0} : {1}", prop.DisplayName, RenderProperty(user1, prop));
}
user1[PropertyConstants.Office].Value = null;
user1[PropertyConstants.Department].Value = "软件中心";
user1["FirstName"].Value = "测试用户";
user1.Commit();
Console.WriteLine("Success!");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
} |