1

有没有办法从对象模型中搜索 MOSS 中的配置文件?我需要搜索在其个人资料上设置了特定值的个人资料,然后为它们执行一些操作。

我需要编写一些可以搜索配置文件数据库并返回匹配配置文件的 c# 代码。基本上,

配置文件列表 = 从配置文件存储中选择配置文件,其中配置文件属性值 = SomeValue

我试图避免以下情况:

 private IEnumerable<UserProfile> SearchProfiles(string value) {
        ServerContext serverContext = ServerContext.GetContext(SPContext.Current.Site);
        UserProfileManager profileManager = new UserProfileManager(serverContext);
        foreach (UserProfile profile in profileManager) {
            if ((string)profile["MyProp"].Value == value) {
                yield return profile;
            }
        }
    }
4

2 回答 2

1

这可以使用 FullTextSqlQuery 类:

FullTextSqlQuery q = new FullTextSqlQuery(ServerContext.Current);
q.ResultTypes = ResultType.RelevantResults;
q.QueryText = "SELECT UserName, Email, PreferredName FROM SCOPE() WHERE \"scope\" = 'People' AND Department = 'IT'";

ResultTableCollection tables = q.Execute();
ResultTable results = tables[ResultType.RelevantResults];

此类允许您查询特定范围(即人员)并使用 WHERE 子句根据属性对其进行过滤,这看起来与常规 Sql Query 基本相同。

为了能够搜索和过滤(自定义)用户配置文件属性,配置文件属性需要在共享服务提供者的元数据设置中有一个映射。大多数开箱即用的用户配置文件属性已经具有这些您必须自己添加的自定义属性。

有关托管属性的更多信息,请点击此处

于 2010-01-09T19:08:15.657 回答
0

两件事情:

  1. 当以提升的权限运行时,我们需要在调用中创建一个新的 SPSite 对象并从那里加载安全上下文。不要使用通过 SPContext.Current.Site 获得的上下文。

    因此:

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
     using (SPSite site = new SPSite("<your site url>"))
     {
      ServerContext context = ServerContext.GetContext(site);
    
      UserProfileManager profileManager = new
    
      UserProfileManager(context);
    
      foreach (UserProfile profile in profileManager)
      {
       // your code
      }
     }
    }
    
  2. 确保应用程序池帐户在 SSP 中具有适当的用户权限。即(使用个人功能,管理用户资料)

于 2010-05-03T12:40:10.680 回答