sharepoint 如何使用timer job 实现列表评论次数
办公教程导读
互联网集市收集整理了【sharepoint 如何使用timer job 实现列表评论次数】办公软件教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3334字,纯文字阅读大概需要5分钟。
办公教程内容图文
![sharepoint 如何使用timer job 实现列表评论次数](/upload/InfoBanner/jiaochengoffice/89/ca09421d7f3a4d18869b09fce4672f4b.jpg)
sharepoint 如何给文档库或自定义列表添加评论功能,添加完评论之后,还有个事情,就是需要统计评论数量。这次主要是以文档库为例,给文档库的文档添加评论后,如何在列表中显示当前文档的评论数量。 思路还是和前面提到的,sharepoint 用timer job 实现文档下载次数,是一样的,也是做一个配置表加一个timer job,定时更新这个评论数。 1。创建一个自定义列表,“评论次数更新表”,字段如下图所示。 其中两个字段,Url 指的是需要更新的列表地址(列表类型不限),UpdateColumn指的是,更新字段的名称。 2。创建一个timer job,类名叫 CommentsCountTimerJob,并且继承SPJobDefinition。 public class CommentsCountTimerJob : SPJobDefinition } public override void Execute(Guid contentDbId) 3。添加一个接收器。 [Guid("7108753c-c802-4200-a77d-5d54f3fa2567")] 4。部署这个timer job。 之后我们返回文档列表,将记事版添加到文档的查看页面,并且添加一些评论,如下图: 再返回到文档列表,等一会评论次数就会更新,将这个文档的评论次数更新为2。并且显示在列表字段中。如下图 其它文档,以及文件夹里面的文档也一样,如果有添加了评论,就会定时更新这个评论次数,到列表中。 其中最主要用到的一点就是,socialCommentManager.GetCount 这个方法,用来统计评论次数。 参考文章:
sharepoint 用timer job 实现文档下载次数
{
public CommentsCountTimerJob(): base(){}
public CommentsCountTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)
: base(jobName, service, server, targetType)
{
public CommentsCountTimerJob(string jobName, SPWebApplication webApplication)
: base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
{
this.Title = jobName;
}
{
int count;
SPSite site = new SPSite("http://moss:8000");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPServiceContext context = SPServiceContext.GetContext(site);
SPList DocumentList;
SocialCommentManager socialCommentManager = new SocialCommentManager(context);
SPList list = web.Lists.TryGetList("评论次数更新表");
foreach (SPListItem item in list.Items)
{
DocumentList = web.GetList(item["Url"].ToString());
foreach (SPListItem DocumentItem in DocumentList.Items)
{
count = socialCommentManager.GetCount(new Uri(web.Url + "/" + DocumentItem.Url));
string columnName = item["UpdateColumn"].ToString();
DocumentItem[columnName] = count;
DocumentItem.Update();
}
}
}
}
public class Feature1EventReceiver : SPFeatureReceiver
{
const string JOB_NAME = "CommentsCountTimerJob";
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site;
if (properties.Feature.Parent is SPWeb)
{ site = ((SPWeb)properties.Feature.Parent).Site; }
else
{ site = (SPSite)properties.Feature.Parent; }
// make sure the job isn't already registered
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == JOB_NAME)
{
job.Delete();
}
}
// install the job
CommentsCountTimerJob Com = new CommentsCountTimerJob(JOB_NAME, site.WebApplication);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 1;
Com.Schedule = schedule;
Com.Update();
}
}
办公教程总结
以上是互联网集市为您收集整理的【sharepoint 如何使用timer job 实现列表评论次数】办公软件教程的全部内容,希望文章能够帮你了解办公软件教程sharepoint 如何使用timer job 实现列表评论次数。 如果觉得互联网集市办公软件教程内容还不错,欢迎将互联网集市网站推荐给好友。
办公教程备注
版权声明:本文内容由互联网用户贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
办公教程手机端
扫描二维码推送至手机访问。