• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

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

        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 可以幫助企業用戶輕松完成日常工作。

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

        本類教程下載

        系統下載排行

        主站蜘蛛池模板: 亚洲色精品VR一区区三区| 亚洲高清有码中文字| 亚洲日韩AV一区二区三区中文 | 毛片免费在线播放| 国产国产成年年人免费看片| 亚洲精品乱码久久久久久按摩 | 一本久到久久亚洲综合| 337p日本欧洲亚洲大胆色噜噜| 国产成人亚洲精品无码AV大片| 永久免费A∨片在线观看| 日本免费一二区在线电影| 亚洲精品国产成人专区| 精品女同一区二区三区免费播放 | 亚洲色精品vr一区二区三区| 亚洲一线产区二线产区区| 成人无码区免费A∨直播| 麻豆成人精品国产免费| 亚洲AV无码久久寂寞少妇| 丁香六月婷婷精品免费观看| 免费无码A片一区二三区| 亚洲精品成人av在线| 91免费国产精品| 亚洲情综合五月天| 最近最新高清免费中文字幕| 吃奶摸下高潮60分钟免费视频| 亚洲日韩在线视频| 亚洲免费在线播放| 亚洲色爱图小说专区| 蜜桃视频在线观看免费视频网站WWW| 久久亚洲国产成人影院网站| 黄页网站在线免费观看| 蜜臀91精品国产免费观看| 成年免费大片黄在线观看com| 免费观看国产小粉嫩喷水| 亚洲а∨天堂久久精品9966| 免费看国产曰批40分钟| 成人黄网站片免费视频 | 69成人免费视频| 亚洲成人高清在线观看| 国产小视频在线观看免费| 久久精品电影免费动漫|