深入浅出SharePoint——TimeJob编程
获取SPWeb实例
方式一 if deployed on farm,we can get spweb by time job title
A define site url in feature template.xml as property,and access it in FeatureActivated event
string url = properties.Feature.Properties[activeSiteUrl].Value;
……
job.Title = displayName + "(" + url.ToLower().Trim() + ")";
B Access spweb by title which contains the site url
string webUrl = Title.Substring(Title.IndexOf("(") + 1).Replace(")", "");
using (SPSite site = new SPSite(webUrl))
方式二 if deployed on web,we can get spweb by feature parent
SPSite currentSite = properties.Feature.Parent as SPSite;
部署:
如果不是第一次部署,一定要重新启动TimerJob服务,新版本的TimerJob应用才会生效。