Scope of a feature activated Custom Sharepoint-Timer Job

有些话、适合烂在心里 提交于 2019-12-11 07:32:45

问题


So I'm developing a custom timer job for sharepoint using the SPJobDefinition.

This job is activated through a feature receiver.

As I understand it the SPJobDefinition runs on the web-application.

if the feature scope is site or web based, is there any way code-wise to determine which site the feature is activated through in the Customer Job?

To get a clearer picture of what I'm trying to achieve, the job itself is a custom "Alert Me" notification job. What I'd like to do, is be able to determine which sites have activated this feature, so as to determine which sites to subscribe to the alerts notifications.

But I have no idea how to determine which sites have this feature activated.

Any help much appreciated.


回答1:


Below is code I've used to do just what you are describing:

    public override void Execute(Guid targetInstanceId)
    {
        foreach (SPSite site in this.WebApplication.Sites)
        {
            try
            {
                if (SPSite.Exists(new Uri(site.Url)) && null != site.Features[FeatureId.AlertMeJob])
                {
                    try
                    {
                        ExecuteJob(site);
                    }
                    catch (Exception ex)
                    {
                        // handle exception
                    }
                }
            }
            finally
            {
                site.Dispose();
            }
        }
    }

FeatureId.AlertMeJob is a GUID representing the Feature with the Feature Receiver that creates the job schedule (if it didn't already exist).



来源:https://stackoverflow.com/questions/3396084/scope-of-a-feature-activated-custom-sharepoint-timer-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!