日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

當前位置:雨林木風下載站 > 辦公軟件教程 > 詳細頁面

SharePoint 開發TimerJob 介紹

SharePoint 開發TimerJob 介紹

更新時間:2024-02-08 文章作者:未知 信息來源:網絡 閱讀次數:

SharePoint發行版本有SharePoint2003、SharePoint2007、Sharepoint 2010、SharePoint2013和SharePoint2016。SharePoint提供了功能強大的團隊協作環境,使得組織能夠在整個組織內部實現整合、組織、查找和提供 SharePoint站點。

項目需要寫TimerJob,以前也大概知道原理,不過,開發過程中,還是遇到一些問題,網上看了好多博客,也有寫的灰常好的,不過,自己還是想再寫一下,也算是給自己一個總結,也算給大家多一個參考吧。

?????? TimerJob項目結構,主要有兩個Class,一個是用來定義TimerJob功能的,一個是用來部署開發好的TimerJob的,分別繼承兩個不同的類。如下圖,先建一個如下結構的項目:

clip_image001

?

文件描述:

TimerJob定義類:ModifyTitle.cs(繼承自SPJobDefinition)

TimerJob安裝類:ModifyTitleInstall.cs(繼承自SPFeatureReceiver)

激活TimerJob的Feature.xml

添加強命名,因為將來生成的dll是要放到GAC里面去的

?

添加引用:

引用Microsoft.SharePoint.dll文件,兩個Class都需要添加下面命名空間

using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration;

?

ModifyTitleInstall

public class ModifyTitleInstall : SPFeatureReceiver

{

const string TimerJobName = "ModifyTitleTimerJob";//TimerJob的標題

//激活TimerJob的方法

public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

SPSite site = properties.Feature.Parent as SPSite;

foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)

{

//如果有相同的TimerJob,先刪除

if (job.Title == TimerJobName)

{

job.Delete();

}

}

ModifyTitle modifyTitle = new ModifyTitle(TimerJobName, site.WebApplication);

SPMinuteSchedule minuteSchedule = new SPMinuteSchedule();//計時器對象

minuteSchedule.BeginSecond = 0;

minuteSchedule.EndSecond = 59;

minuteSchedule.Interval = 1;

modifyTitle.Schedule = minuteSchedule;

modifyTitle.Update();

//throw new NotImplementedException();

}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

{

SPSite site = properties.Feature.Parent as SPSite;

foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)

{

if (job.Title == TimerJobName)

{

job.Delete();

}

}

//throw new NotImplementedException();

}

public override void FeatureInstalled(SPFeatureReceiverProperties properties)

{

//throw new NotImplementedException();

}

public override void FeatureUninstalling(SPFeatureReceiverProperties properties)

{

//throw new NotImplementedException();

}

?

ModifyTitle

public class ModifyTitle : SPJobDefinition

{

public ModifyTitle():base(){}

public ModifyTitle(string TimerName, SPWebApplication webapp) : base(TimerName, webapp, null, SPJobLockType.ContentDatabase)

{

//TimerJob的標題

this.Title = "定期修改Title的TimerJob";

}

public override void Execute(Guid targetInstanceId)

{

SPWebApplication webapp = this.Parent as SPWebApplication;

SPContentDatabase contentDB=webapp.ContentDatabases[targetInstanceId];

foreach (SPItem item in contentDB.Sites[0].RootWeb.Lists["TimerJob"].Items)

{

DateTime dt = Convert.ToDateTime(item["創建時間"].ToString());

item["標題"] = "今天是這個月的第" + dt.Day.ToString() + "天";

item.Update();

}

//base.Execute(targetInstanceId);

}

}

?

Feature.xml(Id是需要重新生成的Guid)

<?xml version="1.0" encoding="utf-8" ?>

Id="f0c813e8-68e0-4ad2-82cd-292b1b7222cd"

Title="Modify Title Timer Job"

Description="Modify Title Timer Job"

Scope="Site"

Hidden="TRUE"

Version="1.0.0.0"

ReceiverAssembly="TimerJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f7436af6afb9480b"

ReceiverClass="TimerJob.ModifyTitleInstall">

?

添加結果:

clip_image003

?

運行結果:無論標題是什么,都改成今天是這個月的第N天。

clip_image005

?

添加配置文件:

<?xml version="1.0" encoding="utf-8" ?>

?

獲取配置文件:

string AAString = ConfigurationManager.AppSettings.Get("AAString");

注:配置文件格式不對的話,可能造成Timer服務啟動錯誤,所以,可以拷一個控制臺程序debug下面的Consoleapp.exe.config文件,然后改成OWSTIMER.exe.config,然后放到12/bin(C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN)下就可以了

?

部署TimerJob腳本:

@echo off

SET TEMPLATE="c:\program files\common files\microsoft shared\web server extensions\12\Template"

Echo Copying files to TEMPLATES directory

xcopy /e /y 12\TEMPLATE\* %TEMPLATE%

Echo Copying TimerJob.dll to GAC

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe" -if bin\TimerJob.dll

iisreset

"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm" -o installfeature -filename TimerJob\feature.xml -force

"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm" -o deactivatefeature -filename TimerJob\feature.xml -url http://localhost -force

"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm" -o activatefeature -filename TimerJob\feature.xml -url http://localhost -force

net stop SPTimerV3

net start SPTimerV3

PAUSE

注:新的TimerJob運行一定要重啟SPTimerV3服務,在windows服務里面,如下圖:

clip_image007

調試:TimerJob程序和WebPart等SharePoint程序,運行的進程不一樣,如果需要調試,需要重新安裝TimerJob,然后附加到SharePoint計時器進程(下圖),進行調試!

clip_image008

體會:

?????? 開發完TimerJob感覺,和SharePoint的東西有一樣的特點,就是代碼開發比較簡單,但是雜七雜八的事情很多,部署、調試起來比較麻煩,而且非常需要細心,如果其間遇到各種bug,可以建議重啟下機器(我就是頭天晚上,各種報錯,轉天就好了)。

?????? 還有就是,我的代碼是SharePoint2007環境開發的,如果在2010或者更高版本,代碼基本是類似的,注意目錄即可,部署方式可能需要PowerShell,可以網上查一下。


Sharepoint 可以幫助企業用戶輕松完成日常工作。

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

主站蜘蛛池模板: 高清国产精品久久 | 天天干视频在线 | jizz日本老师 | 国产一区二区不卡视频 | 日韩激情中文字幕一区二区 | 91精品国产露脸对白 | 久久久久久国产精品三级 | 久久99精品久久久久久园产越南 | 欧美啪啪片 | 青草在线视频 | 欧美特级毛片a够爽 | 欧美成人精品福利网站 | 国产三级在线观看 | 国产福利视频网站 | 国产成+人+综合+亚洲不卡 | 日韩精品一区二区三区毛片 | 看国产一级毛片 | 日本a在线视频 | 88国产精品欧美一区二区三区 | yjizz国产在线视频网 | 国产91精品一区二区麻豆亚洲 | 爱爱视频在线播放 | 激情五月色综合婷婷大片 | 伊人免费在线观看高清版 | 久久综合九色综合91 | 国产成人青青热久免费精品 | 国产第一浮力影院新路线 | 欧美高清在线视频一区二区 | 手机免费在线视频 | 久久精品这里热有精品2015 | 日本久久综合网 | 日本在线观看www | 日日摸夜夜爽久久综合 | 亚洲经典三级 | 色在线看 | 欧美精品在中文字幕 | 久久激情免费视频 | 经典欧美gifxxoo | 一级做a爱过程免费视频麻豆 | 亚洲欧美精品成人久久91 | 日韩a视频在线观看 |