如何在 MOSS 上安装自定义 SharePoint 计时器作业

发布于 2024-10-14 01:19:31 字数 2043 浏览 3 评论 0原文

如何在 MOSS 上安装自定义 SharePoint 计时器作业

您好,我创建了, 自定义 SharePoint 计时器作业, 本文档下面是我的代码。

我编写并安装了很多 网页部件。

但这是我第一次写 MOSS 上的 SharePoint 计时器作业。

我尝试使用 wspBuilder 部署它, 尝试将其复制到 gac, 但该JOB没有出现在JOB列表上 中央管理网站, 中央管理>操作>定时器作业定义,
我如何添加它并在

“中央管理>” 上看到它操作>定时器作业定义 代码。

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using System.IO;
using Microsoft.SharePoint;
namespace WSPBuilderProject1.FeatureCode
{
    public class MyTimerJob : SPJobDefinition
    {
        public MyTimerJob()
            : base()
        {
            this.Title = "My Timer Job";
        }

        public MyTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(jobName, service, server, targetType)
        {
            this.Title = "My Timer Job";
        }

        public MyTimerJob(string jobName, SPWebApplication webApplication)
            : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        {
            this.Title = "My Timer Job";
        }


        public override void Execute(Guid contentDbId)
        {

            using (SPWeb oWeb = SPContext.Current.Site.OpenWeb("/"))
            {
                SPWeb mySite = SPContext.Current.Web;
                mySite.AllowUnsafeUpdates = true;
                SPListItemCollection listItems = mySite.Lists["AuditLogCalculatedData"].Items;
                int itemCount = listItems.Count;

                for (int k = 0; k < itemCount; k++)
                {
                    try
                    {
                        listItems.Delete(k);
                    }
                    catch { }
                }


                    SPListItem item = listItems.Add();

                    item["FileName"] = "roi";
                    item["NumOfEntries"] = 10102;


                    item.Update();

                mySite.AllowUnsafeUpdates = false;

            }

        }
    }
}

How do I install custom SharePoint Timer job on MOSS

Hello I created,
custom SharePoint Timer job,
Below in this document is my code.

I wrote and installed a lot of
webparts.

But this is the first time I write
SharePoint Timer job on MOSS.

i try to deploy it wite wspBuilder,
try to copy it to gac,
But the JOB not appear on the list JOB on
Central Administration site ,
Central Administration > Operations > Timer Job Definitions ,
how can i add it and see it on the ,

Central Administration > Operations > Timer Job Definitions
the code.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using System.IO;
using Microsoft.SharePoint;
namespace WSPBuilderProject1.FeatureCode
{
    public class MyTimerJob : SPJobDefinition
    {
        public MyTimerJob()
            : base()
        {
            this.Title = "My Timer Job";
        }

        public MyTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(jobName, service, server, targetType)
        {
            this.Title = "My Timer Job";
        }

        public MyTimerJob(string jobName, SPWebApplication webApplication)
            : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        {
            this.Title = "My Timer Job";
        }


        public override void Execute(Guid contentDbId)
        {

            using (SPWeb oWeb = SPContext.Current.Site.OpenWeb("/"))
            {
                SPWeb mySite = SPContext.Current.Web;
                mySite.AllowUnsafeUpdates = true;
                SPListItemCollection listItems = mySite.Lists["AuditLogCalculatedData"].Items;
                int itemCount = listItems.Count;

                for (int k = 0; k < itemCount; k++)
                {
                    try
                    {
                        listItems.Delete(k);
                    }
                    catch { }
                }


                    SPListItem item = listItems.Add();

                    item["FileName"] = "roi";
                    item["NumOfEntries"] = 10102;


                    item.Update();

                mySite.AllowUnsafeUpdates = false;

            }

        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薆情海 2024-10-21 01:19:31

这是可以在 FeatureActivated 事件上执行的示例代码

public override void FeatureActivated (SPFeatureReceiverProperties props) {
  SPWebApplication webApp = props.Feature.Parent as SPWebApplication;
  if (webApp == null)
    throw new SPException("Error obtaining reference to Web application.");

  // Ensure the job is not already registered.
  foreach (SPJobDefinition job in webApp.JobDefinitions)
    if (job.Name == JOB_NAME) job.Delete();

  // Install job.
  SharePointWarmupJob warmupJob = new SharePointWarmupJob(webApplication);

  // Schedule the job to run every minute all the time.
  SPMinuteSchedule schedule = new SPMinuteSchedule();
  schedule.BeginSecond = 0;
  schedule.EndSecond = 59;
  schedule.Interval = 1;
  warmupJob.Schedule = schedule;

  // Save changes.
  warmupJob.Update();
}

This is the sample code which can be executed on FeatureActivated event

public override void FeatureActivated (SPFeatureReceiverProperties props) {
  SPWebApplication webApp = props.Feature.Parent as SPWebApplication;
  if (webApp == null)
    throw new SPException("Error obtaining reference to Web application.");

  // Ensure the job is not already registered.
  foreach (SPJobDefinition job in webApp.JobDefinitions)
    if (job.Name == JOB_NAME) job.Delete();

  // Install job.
  SharePointWarmupJob warmupJob = new SharePointWarmupJob(webApplication);

  // Schedule the job to run every minute all the time.
  SPMinuteSchedule schedule = new SPMinuteSchedule();
  schedule.BeginSecond = 0;
  schedule.EndSecond = 59;
  schedule.Interval = 1;
  warmupJob.Schedule = schedule;

  // Save changes.
  warmupJob.Update();
}
绿光 2024-10-21 01:19:31

解决方案

如果您仔细阅读本文,会发现一个压缩的解决方案文件 (TaskLogger_CustomTimerJob.zip )您可以自己使用和编译。

VS2008会提示你将项目转换为2008,只需执行并编译即可。

构建项目

您无法构建的问题出在文件 BuildSharePointPackage.Targets 中。 MakeCabPath 对于您的环境无效。我的 makecab.exe 位于 C:\Windows\system32 路径中。我尝试更改路径并重建,但它不起作用,它以某种方式尝试使用旧位置。所以我只是将 makecab.exe 复制到 C:\Program Files\Microsoft Cabinet SDK\bin 并成功构建。

WSPBuilder

此外,您可能希望使用 WSPBuilder 来减轻创建 SharePoint 解决方案的痛苦。它安装 Visual Studio 扩展,您可以使用它来制作 wsp 文件并从 Visual Studio 进行部署。 在此处下载 WSPBuilder,并使用 Visual Studio 外接程序演练

The solution

If you read down the article, there is a zipped solution file (TaskLogger_CustomTimerJob.zip) which you can use and compile yourself.

VS2008 will prompt you to convert project to 2008, just do it and compile.

Building the project

The problem you can't build lies within file BuildSharePointPackage.Targets. MakeCabPath is not valid for your environment. My makecab.exe lies in C:\Windows\system32 path. I tried to change path and rebuild, but it didn't work, it somehow tried to use the old location. So i just copied makecab.exe to C:\Program Files\Microsoft Cabinet SDK\bin and it builds sucessfully.

WSPBuilder

Also, you may want to use WSPBuilder to alleviate the pain on creating SharePoint solutions. It installs visual studio extension which you can use to make wsp file and deploy from visual studio. Download WSPBuilder here, and use Walkthrough of the Visual Studio Add-in

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文