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种,一种是文档库 ...
随机推荐
- STM32的CRC32 实现代码 -- Ether
uint32_t reverse_32( uint32_t data ) { asm("rbit r0,r0"); return data; } ; uint32_t crc32_ ...
- 分享下使用 svn,测试服务器代码自动更新、线上服务器代码手动更新的配置经验
分享下使用 svn,测试服务器代码自动更新.线上服务器代码手动更新的配置经验 利用SVN的POST-COMMIT钩子自动部署代码 Linux SVN 命令详解 Linux SVN 命令详解2 使用sv ...
- [置顶] 从零开始学C++之STL(二):实现简单容器模板类Vec(vector capacity 增长问题、allocator 内存分配器)
首先,vector 在VC 2008 中的实现比较复杂,虽然vector 的声明跟VC6.0 是一致的,如下: C++ Code 1 2 template < class _Ty, ...
- 使用Axure RP原型设计实践01,使用概述
首先认识Axure RP Pro 7.0软件的默认界面布局.最上面的是工具栏区域,左侧上方的是网站地图区域(sitemap),左侧中部的是部件区域(Widgets),左侧下方的是模板区域(Master ...
- 在Visual Studio中使用用例图描述系统与参与者间的关系
"用例图"用来描述谁用系统,用系统做什么.用例图不涉及使用细节,只用来描述使用人员和系统的关系,也不涉及行动的顺序.一起来体验. 使用Visual Studio 2012创建解决方 ...
- 关于电商ERP的想法
原文地址: http://www.chinaodoo.net/thread-465-1-1.html 试用了下odoo的淘宝订单处理模块,从整个业务流程上已经打通,如果要求不是很高的话,现有的功能基本 ...
- C#编程(十六)----------匿名类型
匿名类型 var和new关键字一起使用,可以创建匿名类型. 匿名类型提供了一种方便的方法,可用来将一组只读属性封装到单个对象中,而无需首先显式定义一个类型. 类型名由编译器生成,并且不能在源代码级使用 ...
- ANDROID DisplayManager 服务解析一
from://http://blog.csdn.net/goohong/article/details/8536102 http://www.tuicool.com/articles/FJVFnu A ...
- 关于struts2种的action运行两次,或多次,或反复运行的bug
今天在做项目的时候发现一个bug,就是action会莫名其妙的运行两次.网上搜了非常多帖子,关于这个问题也得到了一些处理方法,可是没有我想要的,造成运行两次活多次的问题呢,有非常多种原因,我在这里仅仅 ...
- WCF:该不该用枚举值
WCF支持枚举,不过在个别场景下会出现服务消费失败,如:传递或返回的枚举值(本质是int或其它)没有在枚举中定义.这种异常还很难定位,出现这种情况一般是因为BUG,因此简单的放弃使用枚举可能不是一个明 ...