创建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. webkit事件处理

    1,概述 原文地址:http://blog.csdn.net/awebkit/article/details/8493716 浏览器处理事件一般有两个过程,捕获过程和冒泡过程,这是由addEventL ...

  2. [LeetCode] 桶排序的特殊解,例 Sort Color

    Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...

  3. 让我们一起Go(十)

    前言: 本系列还没流产,继续难产中,哈哈,只怪我没专心,在期间又偷偷去学了python,ruby,scala,haskell这几种语言,如果你不幸是本系列的读者,那么你得慢慢等后面的了,等不及可以过几 ...

  4. .NET基金会开源项目

      .NET Compiler Platform ("Roslyn") .NET Core 5 .NET Micro Framework .NET SDK For Hadoop A ...

  5. webgame设计之功能模块的代理模式

    原文地址:http://chengduyi.com/blog/?post=27 在游戏设计中,通常会将一些实现了具体功能的模块进行封装,达到重用的目的.这些功能模块包括:1.网络通信模块(实现连接,断 ...

  6. [IR] Tolerant Retrieval & Spelling Correction & Language Model

    Dictionary不一定是个list,它可以是多种形式. 放弃Hash的原因: 通常,tree是比较适合的结构. From: http://www.cnblogs.com/v-July-v/arch ...

  7. 下载最新Android代码的方法

    之前我是去Android官方网站下载最新Android代码,但是这种方法需要FQ,而且有时候FQ又不太方便,今天我发现一个不错的网站,是清华大学搞的,跟Android官方的代码基本保持同步,而且下载方 ...

  8. ShortcutMapper – 热门应用程序的可视化快捷键

    ShortcutMapper 是一个流行应用程序的键盘快捷键映射.该应用程序使用 Ajax 调用来加载键盘和应用程序数据.首先,试图找到一个在线资源,其中列出了每个平台的所有应用程序快捷方式.然后你可 ...

  9. Android OpenGL 基础入门

    Android 自从2.2 版本之后之后开始支持OpenGL,在没有支持OpenGL 的 GPU的情况下,也可以使用(通过软件来模拟).在Android上使用Opengl操作的对象是GLSurface ...

  10. Android学习笔记(第一篇)编写第一个程序Hello World+Activity

    PS:终于开始正式的搞Android了...无人带的一介菜鸟,我还是自己默默的努力吧... 学习内容: 1.编写第一个Hello World程序..   学习Android,那么就需要有一个编译器来集 ...