SharePoint 2013-CSOM-列出事件处理程序-同步Excel [英] SharePoint 2013 - CSOM - List Event handlers - Synchronize Excel

查看:61
本文介绍了SharePoint 2013-CSOM-列出事件处理程序-同步Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲切的提供者指针

1)使用CSOM-为更新/添加/删除的列表项添加事件接收器

1) Using CSOM - Add Event Receivers for List Item Updated/Added/Deleted

2)使用CSOM-更新(或同步)Excel(或仅更新存储在文档库中的Excel)

2) Using CSOM - Update (or Synchronize) Excel (or simply update an excel stored in a document library)

原因:

针对多个大型(超过5k个项目)列表生成报告.目前,我们正在导出到excel,然后应用自定义公式或在其之上构建图表/数据透视图.

To generate reports against multiple large (5k+ items) lists. Currently, we are exporting to excel and then applying custom formulas or building charts/pivots on top of it.

我们要追求的解决方案是在共享点(仪表板)的页面上显示Excel对象(如Pivort或Charts),而无需在后台手动更新excel.因此,寻找相关列表更新后自动同步excel的选项.

Solution we want to pursue is display Excel objects (like Pivort or Charts) on page in sharepoint (Dashboard) and without manually upating excel behind the scene. Hence, looking for options to automatically sync-up excel once it's associated list is updated.

推荐答案

1.查看下面的代码片段,以使用CSOM将事件接收器附加到列表中.

1. Check the code snippet below to attach event receiver to list using CSOM.

using Microsoft.SharePoint.Client;
using System;
using System.Net;

private static void AttachEventReceiver()
{
	var userName = "<<UserNameWithoutDomainName>>";
	var password = "<<Password>>";
	string domain = "<<DomainName>>";
	string webUrl = "<<WebUrl>>";

	using (var context = new ClientContext(webUrl))
	{
		context.Credentials = new NetworkCredential(userName, password, domain);
		var list = context.Web.Lists.GetByTitle("<<ListName>>");
		var eventReceivers = list.EventReceivers;
		context.Load(eventReceivers);
		context.ExecuteQuery();

		EventReceiverType eventType = EventReceiverType.ItemUpdated;    //event type (ItemAdded / ItemUpdated)
		string receiverAssembly = "<<FullyQualifiedAssemblyName>>";     //Example: <<AssemblyName>>, Version=<<AssemblyVersion>>, Culture=neutral, PublicKeyToken=<<PublicKeyToken>>
		string receiverClass = "<<ReceiverClassNameStartingWithNamespaceName>>";    //Example: <<NamespaceName>>.<<ClassName>>
		string receiverName = "<<ReceiverName>>";       //you can give any name

		bool isEventReceiverAlreadyAssociated = false;
		foreach (var eventReceiver in eventReceivers)
		{
			if (eventReceiver.EventType == eventType
			&& string.Compare(eventReceiver.ReceiverAssembly, receiverAssembly, StringComparison.OrdinalIgnoreCase) == 0
			&& string.Compare(eventReceiver.ReceiverClass, receiverClass, StringComparison.OrdinalIgnoreCase) == 0
			&& string.Compare(eventReceiver.ReceiverName, receiverName, StringComparison.OrdinalIgnoreCase) == 0
			)
			{
				isEventReceiverAlreadyAssociated = true;
			}
		}

		if (!isEventReceiverAlreadyAssociated)
		{
			EventReceiverDefinitionCreationInformation eventReceiver
			= new EventReceiverDefinitionCreationInformation
			{
				EventType = eventType,
				ReceiverAssembly = receiverAssembly,
				ReceiverClass = receiverClass,
				ReceiverName = receiverName,
			};

			list.EventReceivers.Add(eventReceiver);
			context.ExecuteQuery();
		}
	}
}

2.如果要基于列表数据获得一些图表报表,我们还可以使用一些带有REST API的jQuery图表插件来实现它,那么我们通常不需要更新excel文件.

2. If you want to achieve some chart report base on the list data, we can also use some jQuery chart plugins with REST API to achieve it, then we don't need update the excel file usually.

SharePoint列表到JQuery图表SharePoint加载项

https://code.msdn.microsoft.com/office/SharePoint-List -to-JQuery-90bfd45f

最好的问候,

丹尼斯


这篇关于SharePoint 2013-CSOM-列出事件处理程序-同步Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆