时间:2020-09-04 11:38作者:admin来源:未知人气:278我要评论(0)
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中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database schema doesn't match the TargetSchema"的解决方案InfoPath Error “此文档库已经被重命名或删除,或者网络问题导致文件无法保存…” 的解决方案SharePoint 2013 App概述How to Shrink SharePoint Content Database Log File?Project Web App Feature无法开启的解决方案
热门文章 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”
最新文章
SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件
如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database s
人气排行 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”SharePoint 2013 安装图解 SharePoint安装步骤图解教程SharePoint 如何开启访问请求[SharePoint入门教程]一SharePoint概述[SharePoint入门教程]一创建SharePoint母版页
盖楼回复X
(您的评论需要经过审核才能显示)
查看所有0条评论>>