创建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. js apply/call/caller/callee/bind使用方法与区别分析

    一.call 方法 调用一个对象的一个方法,以另一个对象替换当前对象(其实就是更改对象的内部指针,即改变对象的this指向的内容). Js代码 call([thisObj[,arg1[, arg2[, ...

  2. 如何克隆kvm虚拟机

    关于如何使用kvm虚拟化技术创建虚拟机,这里有一系列博客讲的已经非常清楚了,这里不再赘述,不过其中有些小坑可能需要大家注意: 0. 写在创建虚拟机之前(即教程的系列三之前) 1. 确认防火墙是否关闭, ...

  3. Unity 脚本系统

    什么是脚本?脚本是一个 MonoBehavior, 继承关系是 MonoBehavior -> Behavior -> Component -> Object GameObject ...

  4. C#结构体的特点浅析

    C#结构体的特点浅析 2009-08-13 11:18 意识的偏差 百度空间 字号:T | T   C#结构体的特点有哪些呢?C#结构体与类的区别是什么呢?本文就向你介绍相关的内容. AD:   C# ...

  5. Unity 3D 一个简单的角色控制脚本

    之所以写这个脚本,是因为我想起了我还是新手的时候,那时为了一个角色控制脚本百度了半天还是一无所获,因为看不懂啊,都写的太高级了 希望这个脚本能够帮助那些 像曾经的我一样迷失于代码中的新手们能够清晰的理 ...

  6. Java中接口式的匿名内部类的构造方法

    在使用多线程的时候,时常会使用两种方式实现,一种是直接继承Thread类来实现多线程,另外一种就是实现Runnable接口. 我们都知道,接口是没有构造方法的,同时匿名内部类也是没有构造方法的.原因有 ...

  7. [Architect] Abp 框架原理解析(1) Module

    本节目录 Abp介绍 Abp源码分析 代码实现 Abp介绍 学习了一段时间的Abp,领略了一下前辈的架构.总结还是SOLID,降低耦合性. 虽然从架构上说甚至不依赖于DI框架,但实际上在基础框架中还是 ...

  8. [Tool] 源代码管理之Git

    本节目录 什么是Git 什么是GitHub 安装Git GitHub之Repository GitHub之托管页面 常用Git 命令 什么是Git 由于现在的开发多人协同办公,因此出现源代码管理工具 ...

  9. H5案例学习笔记

    ★基础篇     增加主体结构元素    

  10. ASP.NET的路由

    之前在探讨ASP.NET  MVC的路由时,无意发现原本ASP.NET也有路由机制的.在学习MVC的路由时觉得这部分的资料不太多,不怎么充实(也许是我不懂得去看微软的官方文档).后来也尝试一下ASP. ...