有关使用休息查找重复项的问题 [英] Question about using rest to find duplicates
问题描述
不确定此代码,但我在另一篇论坛帖子中找到了它.
Not sure about this code, but I found it on another forum post.
https://social.msdn.microsoft.com/Forums/office/en-US/fce9b12a-931e-4058-8190-cb1bd081c9d7/check-duplicate-items-in-the-sharepoint-list-programmatically?forum=sharepointdevelopmentprevious
他们提到要使用此代码:
they mention to use this code:
< OrderBy> < FieldRef Name ="名称" /> < FieldRef Name =优先级";升序="FALSE". /> </OrderBy>
<OrderBy> <FieldRef Name="Name" /> <FieldRef Name="Priority" Ascending="FALSE" /> </OrderBy>
字符串重复= null;
string duplicate = null;
SPListItemCollection项目= mylist.GetItems(查询);
SPListItemCollection items = mylist.GetItems(query);
if(items.Count> 0)
{
foreach(项目中的SPListItem项)
{
字符串标题= Convert.Tostring(item ["Name"]));
if(items.Count > 0)
{
foreach(SPListItem item in items)
{
string title = Convert.Tostring(item["Name"]);
if(标题==重复)
{
重复= Convert.ToString(item ["Name"]]);
item.Delete();
}
}}
if(title == duplicate)
{
duplicate = Convert.ToString(item["Name"]);
item.Delete();
}
}}
在SPS2013中可以使用吗?
Is this useable in SPS2013?
该代码放在哪里?
我不想删除重复的邮件,我希望将电子邮件发送给批准人,让他们知道可能的 副本已提交.
I dont want to Delete the Duplicate I want an Email to be sent to an approver letting them know a possible duplicate has been submitted.
推荐答案
您好,
这是供您参考的步骤.
通过Visual Studio(2013/2015)创建服务器场解决方案.
创建事件接收器(如果您选择了自定义列表"在监视自定义列表).
更新Elements.xml以指定您要使用的列表要添加事件接收器.
将代码添加到事件接收器.
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPListItem item = properties.ListItem;
SPQuery query = new SPQuery();
//FieldRef Name='Title' the field which you want to check duplicate
query.Query = @"<Where><Eq><FieldRef Name='Title'/>" +
"<Value Type='Text'>" + item.Title + "</Value></Eq></Where>";
SPListItemCollection items = properties.List.GetItems(query);
if (items.Count > 1)
{
StringDictionary Headers = new StringDictionary();
Headers.Add("to", "usera@contoso.com");
Headers.Add("from", "administrator@contoso.com");
Headers.Add("subject", "not default");
SPUtility.SendEmail(properties.Web, Headers, "duplicate record" + item.Title + item.Url + "");
}
}
将解决方案部署到您的服务器场(网站集)
结果:
最好的问候,
Lee
这篇关于有关使用休息查找重复项的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!