创建Time Job

继承继承SPJobDefinition 并且实现里边的 Execute方法

部署

可以手动部署,把程序集放到GAC,手动激活feature

如果部署的时候说feature已经存在,在feature的XML里面添加代码 AlwaysForceInstall="TRUE",如下

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
AlwaysForceInstall="TRUE"
Title="Time Job for Find Document"
Description="Custom Feature for Time job">
</Feature>

安装

写到Feature,添加或者删除

更新

需要重新启动Windows SharePoint Services Timer 服务

调试

把OWSTIMER.EXE添加到进程

定义Timejob代码

引用

using Microsoft.SharePoint.Administration;

using Microsoft.SharePoint.Utilities;

public class FindDocument:SPJobDefinition
{
public FindDocument()
: base()
{
} public FindDocument(string jobName, SPWebApplication webapp)
: base(jobName, webapp, null, SPJobLockType.ContentDatabase)
{
this.Title = Constants.FDJobName;
} public override void Execute(Guid targetInstanceId)
{
SPWebApplication webapp = this.Parent as SPWebApplication;
SPContentDatabase contentDb = webapp.ContentDatabases[targetInstanceId]; string webUrl = this.Properties["WebUrl"].ToString();
using (SPSite site = new SPSite(webUrl))
{
using (SPWeb web = site.OpenWeb())
{
//Send mail to somebody
SPUtility.SendEmail(web, false, false,
"xxx@xxx.com", "E-mail title",
"E-mail body");
//udpate list
SPList list = web.Lists["Test"];
SPListItem item = list.Items[0];
item["Title"] = "Date " + DateTime.Now.ToString();
item.SystemUpdate();
}
}
} //If active feature error, please active feature manually.
protected override bool HasAdditionalUpdateAccess()
{
return true;
}
}

安装卸载Timejob代码

引用

using Microsoft.SharePoint.Administration;

public class TimeJobFeatureEventReceiver : SPFeatureReceiver
{
// Uncomment the method below to handle the event raised after a feature has been activated.
const string JobName = Constants.FDJobName;
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
DeleteJob(web); // Delete Job if already Exists
CreateJob(web); // Create new Job
} public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
DeleteJob(properties.Feature.Parent as SPWeb); // Delete the Job
} private static void DeleteJob(SPWeb web)
{
foreach (SPJobDefinition job in web.Site.WebApplication.JobDefinitions)
if (job.Name == JobName)
job.Delete();
} private static void CreateJob(SPWeb web)
{ TimeJob.Jobs.FindDocument job = new TimeJob.Jobs.FindDocument(JobName, web.Site.WebApplication);
job.Properties.Add("WebUrl", web.Url);
SPDailySchedule schedule = new SPDailySchedule();
schedule.BeginHour = 16;
schedule.BeginMinute = 00;
schedule.EndHour = 16;
schedule.EndMinute = 30;
job.Schedule = schedule;
job.Update();
}
}

  

Sharepoint 2013 创建TimeJob 自动发送邮件的更多相关文章

  1. SharePoint 2013创建WCF REST Service

    SharePoint 2013为开发者提供了丰富的REST API,方便了我们在客户端操作List中的数据.当然我们也可以在SharePoint 2013中创建自定义的REST Service,比如通 ...

  2. SharePoint 2013 创建搜索中心及搜索设置

    本文没有太多深奥的东西,只是简单的搜索配置,如果你已经掌握请略过本文. 好了,进入内容简介,众所周知,搜索是SharePoint一大特性,下面,我们简单介绍下搜索中心的创建. 1.创建Search子网 ...

  3. SharePoint 2013 创建一个搜索中心和搜索设置

    这篇文章不是太多深奥的东西,只是一个简单的搜索配置,假设你已经有了,请跳过这篇文章. 行,输入信息,大家都知道,搜索SharePoint一个主要特征.下列,我们在搜索中心创建个人资料. 1.创建Sea ...

  4. SharePoint 2013 创建 Site Collection

    在之前的文章中,通过SharePoint Central Administration 创建了Web Application.在这篇文章中将继续SharePoint 2013之旅——还是以Step B ...

  5. SharePoint 2013 创建Web Application

    今天继续SharePoint 2013 的探索之旅,之前几篇文章分析了SharePoint 2013的物理拓扑结构,安装,以及逻辑体系结构.在这篇文章中,我将继续Step By Step形式演示如何在 ...

  6. sharepoint 2013创建外部内容类型并创建外部列表

    步骤: 1.如何:基于 SQL Server 表创建外部内容类型 How to: Create an External Content Type Based on a SQL Server Table ...

  7. SharePoint 2013创建应用程序时IIS端口文件夹下没文件

    最近SharePoint 2007迁移到2013的时候,碰到创建应用程序时IIS端口文件夹下没文件的问题,网上找了大把的原因,终于在这里找到了解决方案: Fix: 1. Open IIS on the ...

  8. sharepoint 2013 创建母版页

    一.创建新的母版页, 并添加了新的样式表 1.从CodePlex 上获得Starter Master Pages for SharePoint 2010 或复制以下母版代码 <%@Master  ...

  9. SharePoint 2013 创建web应用程序报错"This page can’t be displayed"

    错误描述 This page can’t be displayed •Make sure the web address http://centeradmin is correct. •Look fo ...

随机推荐

  1. new/delete和malloc/free的区别

    通俗易懂版本:http://zhidao.baidu.com/question/86185100 1 new/delete和malloc/free最大区别是对对象的理解. 如果你使用 Foo* foo ...

  2. js判定IE

    var ie=!-[1,]; 这句话对于多数前端来说都很熟悉,遇到判定是否是ie浏览器就用这个,但是对于由来以及为什么可能没有深入了解过. 短短6个bytes就做了判定.这个表达式是利用IE和标准浏览 ...

  3. VMware下OS X Yosemite安装VMsvga2桌面黑屏解决方法

    VMsvga2目前并不支持Yosemite,如果安装的话进入桌面除了顶部菜单,全部黑屏.通过顶部菜单打开的大部分应用都会立刻奔溃关闭.参考以下步骤可以解决问题: 1.下载VMsvga2的uninsta ...

  4. 测试GeoGebra博客

    已知函数 \(\textit{f}(\textit{x})=2\textit{m}\ln\textit{x}-\textit{x}^2\), \(\textit{g}(\textit{x})=\tex ...

  5. actionbar部分设置:colorPrimary colorPrimaryDark colorAccent 下部阴影

    去除actionbar下阴影: <item name="android:windowContentOverlay">@null</item>

  6. Unity3d 音效模块相关

    关于Unity的音效方面,主要关注以下3个类: Audio Clip : audio data,导入到unity中的音频文件都是audio clip. Audio Sources : 挂载这audio ...

  7. bootstrap插件学习-bootstrap.tab.js

    先看bootstrap-tab.js的结构 var Tab = function ( element ) {} //构造器 Tab.prototype ={} //构造器的原型 $.fn.tab = ...

  8. 如何拿到国内IT巨头的Offer

    感觉写的很真实,分享一下.原文链接:http://jingyan.baidu.com/article/72ee561aa16d23e16138df3d.html 不久前,byvoid面阿里星计划的面试 ...

  9. CentOS6.5菜鸟之旅:安装输入法(小呀小企鹅)

    一.前言 假如在登录系统的时候语言选择了中文,那么是系统会自带ibus的中文输入法.但由于我打算用英文版,于是就被小企鹅输入法(FCITX)折腾了两个晚上. 二.检查系统编码 在bash中输入 loc ...

  10. 【Coding地址汇总】2016年沈航软工学生项目主页

    同学们把自己的coding主页链接贴在评论里,要求格式"班号+学号+coding主页链接",如: "1301+13061193 + https://coding.net/ ...