class Program
{
static void Main(string[] args)
{
try
{
using (SPSite site = new SPSite("http://ianzhang/"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
if (profileManager.UserExists(site.OpenWeb().CurrentUser.LoginName))
{
UserProfile user1 = profileManager.GetUserProfile(@"ianzhang/administrator");
Console.WriteLine("Profile {0}", user1.MultiloginAccounts[0]);
foreach (Property prop in profileManager.Properties)
{
Console.WriteLine("/t{0} : {1}", prop.DisplayName, RenderProperty(user1, prop));
}
}
}
}
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();
}
}
如果成项查询某一账号的具体信息,则该账号需要在moss中创建“我的网站”才可以查询到,否则
profileManager.UserExists(site.OpenWeb().CurrentUser.LoginName)=false