SharePoint中Rating相关的字段。
Copy below:
Gone through the problem an got the relevant answer also made blog on it so visit the blog post
Some of the important aspects covered are described breifly as follows.
To rate an Item for the first time by a user the following fields should be modified with the respective field values:
- item["RatingCount"]:
This field stores the number of users who have rated the item its value should be incremented.
- item["Ratings"]:
A field which stores the user ratings in CSV string format should add the new users rating like.
int
NewRating = 4; //any desired number from 1 to 5.item["Ratings"] += NewRating + ",";
- item["AverageRating"]:
This field stores the average of the ratings given by all the rated users. Simple weighted average calculation formulas can be implemented which is
float
OldAverage = item["AverageRating"] == null ? 0 : float.Parse(item["AverageRating"].ToString());int
OldNumberOfRatings = item["RatingCount"] == null ? 0 : int.Parse(item["RatingCount"].ToString());int
NewNumberOfRatings = OldNumberOfRatings + 1;float
NewAverage = OldAverage + ( ( NewRating - OldAverage ) / NewNumberOfRatings);//Or.
float
NewAverage = ( ( OldAverage * OldNumberOfRatings ) + NewRating ) / NewNumberOfRatings;item["AverageRating"] = NewAverage;
- item["RatedBy"]:
This field stores the user information in form of array of FieldUserValue which can be modified using following code
FieldUserValue[] ratedUsers = item["RatedBy"] as
FieldUserValue[];//where ratedUsers becomes an array of users who have already rated.
List<FieldUserValue> newUsersRated = new
List<FieldUserValue>();if (ratedUsers != null)
foreach (FieldUserValue ratedUser in ratedUsers)
newUsersRated.Add(ratedUser);
newUsersRated.Add(FieldUserValue.FromUser(user.LoginName));
item["RatedBy"] = newUsersRated;
To Rerate the item for a user who has already rated it before you need to first find the user index (say int userIndex) in the item["RatedBy"] field then change the following fields:
- item["Ratings"]:
Change the user rating in this CSV string by use of userIndex.
FieldUserValue[] ratedUsers = item["RatedBy"] as
FieldUserValue[];for (int i = 0; i < ratedUsers.Length; i++)
if (ratedUsers[i].LookupValue == user.Title)
int userIndex = i;
string[] userRatings = item["Ratings"].split(',');
int
OldRating = int.Parse(userRatings[userIndex]);int
NewRating = 3; //any desired number from 1 to 5.userRatings[userIndex] = NewRating.ToString();
string ratings = userRatings.Join(',', userRatings);
item["Ratings"] = ratings;
- item["AverageRating"]:
change the average value using formula
float
OldAverage = item["AverageRating"];int
NumberOfRatings = item["RatingCount"];float
NewAverage = OldAverage + ( ( NewRating - OldRating ) / NumberOfRatings );item["AverageRating"] = NewAverage;
SharePoint中Rating相关的字段。的更多相关文章
- sharepoint中的YesNo字段
sharepoint中的YesNo字段实际上是一个Boolean字段,性格有点特别,如果IsShow是一个YesNo字段,使用caml查询的时候值为”1“(Yes)”0“(No),Item[IsSho ...
- Oracle中的自连接(self join)-当表中的某一个字段与这个表中另外字段的相关时,我们可能用到自连接。
http://blog.163.com/wkyuyang_001/blog/static/10802122820091751049479/ 当表中的某一个字段与这个表中另外字段的相关时,我们可能用到自 ...
- 6月20日 Django中ORM介绍和字段、字段参数、相关操作
一.Django中ORM介绍和字段及字段参数 二.Django ORM 常用字段和参数 三.Django ORM执行原生SQL.在Python脚本中调用Django环境.Django终端打印SQL语句 ...
- Sharepoint 2013列表视图和字段权限扩展插件(免费下载)!
记得2014年春节期间,有博客园的网友通过QQ向我咨询Sharepoint 2013列表视图和字段权限扩展,因为之前他看到我博客介绍Sharepoint 2010列表视图和字段的权限控制扩展使用,问有 ...
- Sharepoint中有关文件夹的操作
1.GetItemsWithUniquePermissions根据返回数量和是否返回文件夹获取唯一权限的列表项集合 对于SharePoint对象模型中SPList的GetItemsWithUnique ...
- SharePoint中使用Visio Service展示业务数据
SharePoint中可以通过Visio Service可以在浏览器中查看Visio图,功能部署到系统中,一切安好. 而现实总是很折磨人,使用该功能后,相关使用者随后提出,Visio图能否与我的业务数 ...
- SharePoint中新创建的Web Application在浏览器中报404错误
问题描述:在安装完成SharePoint 2010后,进入Central Administration,创建一个新的Web Application,可以正常创建,但访问时却返回404. 平台环境:Wi ...
- 理解CSV文件以及ABAP中的相关操作
在很多ABAP开发中,我们使用CSV文件,有时候,关于CSV文件本身的一些问题使人迷惑.它仅仅是一种被逗号分割的文本文档吗? 让我们先来看看接下来可能要处理的几个相关组件的词汇的语义. Separat ...
- 在SharePoint中创建可自定义属性的文件夹
概况 阅读时间:约5分钟 适用版本:SharePoint Server 2010及以上 面向用户:普通用户.管理员.开发人员 难度指数:★★★☆☆ SharePoint中的文件夹分为2种,一种是文档库 ...
随机推荐
- Who is YaoGe.(搞笑篇)
耀哥是google的大牛.主持google各种牛逼分布式系统的设计,比方Mapreduce之类的,关于大神的传说,如同春哥一样多,当然,有些传说仅仅有程序猿能明确! 耀哥当初面试Google时.被 ...
- Android WebView加载Html右边空白问题的解决方案
用WebView显示Html时,右边会出现一条空白区,如下图所示: 最开始的时候,认为是网页本身的空白. 后来发现网页本身无问题,且这个空白区是跟Scroll Bar 的位置和粗细比较相符,于是去控制 ...
- Visio中如何绘制黑白图像
- Java知识回顾 (3)运算符
位运算符 Java定义了位运算符,应用于整数类型(int),长整型(long),短整型(short),字符型(char),和字节型(byte)等类型. 位运算符作用在所有的位上,并且按位运算.假设a ...
- android studio一直卡在Gradle:Executing tasks
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=554227 新建了个hello world项目,运行就卡在Gradle:Exec ...
- WordPress主题开发实例:产品展示
产品展示用到文章和缩略图功能 实现步骤: 一.创建分类 后台创建文章分类:产品中心 二.开启缩略图功能 在主题的functions.php中,添加一段代码,代码如下: add_theme_suppor ...
- WordPress主题开发:评论框
方法一:调出内置评论框: 文章开启评论: 页面开启评论:(注意:如果使用的是插件,点快速编辑是没有“允许评论”可勾选的) 在对应的地方,插入 <?php comments_template(); ...
- 玩转Eclipse — 自动代码生成的Java Code Template
文章转载地址:点击打开链接 当代码写到一定程度之后,就会发现很多代码都被重复地敲了N多遍,甚至毫不夸张地说:闭着眼睛都能敲出来.大量地敲这些重复地代码,除了锻炼敲键盘的速度,基本上没有其他益处,但是长 ...
- 详细解读Volley(三)—— ImageLoader & NetworkImageView
ImageLoader是一个加载网络图片的封装类,其内部还是由ImageRequest来实现的.但因为源码中没有提供磁盘缓存的设置,所以咱们还需要去源码中进行修改,让我们可以更加自如的设定是否进行磁盘 ...
- SeekBar的用法和自定义滑块的样式
SeekBar继承自ProgressBar,所以基本一样,我们自定义一般也就是顶一个滑块的图片而已. 布局文件 <RelativeLayout xmlns:android="http: ...