如何在 MOSS 上安装自定义 SharePoint 计时器作业
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是可以在
FeatureActivated
事件上执行的示例代码This is the sample code which can be executed on
FeatureActivated
event解决方案
如果您仔细阅读本文,会发现一个压缩的解决方案文件 (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 toC:\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