开发者

Compile Audience via API with SharePoint 2010 (not 2007)

I can't seem to get this thing to run. I believe it's mainly related to the first parameter for ApplicationId. I can't figure out what ID to enter. I get a return result of 4 which means bad ID. All the samples out there were for 2007 and used SearchContext and is deprecated. Anyone?

 public void CompileAudience(SPServiceContext serviceContext, AudienceManager audienceMgr, string AudienceName)
    {   
        try
        {
            int RunJob = -1;

            CustomMaintenanceTimerJobLogging.LogInfo(CustomMaintenanceTimerJobLogging.CategoryType.AudienceCompile, String.Format("Started compiling the audience '{0}' at {1}", AudienceName, DateTime.Now.ToShortTimeString()));

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // Access the service proxy instance of search application proxy.
                SearchServiceApplicati开发者_如何学ConProxy searchApplicationProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;

                // Service Application Info object to retrieve the application id for the search service.
                SearchServiceApplicationInfo searchApplicationInfo = searchApplicationProxy.GetSearchServiceApplicationInfo();

                string[] args = new string[4];
                args[0] = searchApplicationInfo.SearchServiceApplicationId.ToString();
                args[1] = "1";  // 1=Start compile, 0=Stop
                args[2] = "1";  // 1=Full, 0=Incremental  
                args[3] = AudienceName;

                RunJob = AudienceJob.RunAudienceJob(args);
            });

            CustomMaintenanceTimerJobLogging.LogInfo(CustomMaintenanceTimerJobLogging.CategoryType.AudienceCompile, String.Format("Completed compiling the audience '{0}' at {1} with a Result Code of {2} (0 means no errors)", AudienceName, DateTime.Now.ToShortTimeString(), RunJob));
        }
        catch (Exception ex)
        {
            CustomMaintenanceTimerJobLogging.LogError(CustomMaintenanceTimerJobLogging.CategoryType.AudienceCompile, ex);
        }
    }


Please check out my blog post: http://blog.repsaj.nl/?p=258. That's all you need to get there. The application ID you need to pass isn't the search service id, but the user profile id. It takes some reflection to find that ID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜