从何处使用TokenHelper类用于SharePoint Online中的客户端上下文?

时间:2017-08-14 09:48:16

标签: sharepoint sharepoint-online csom

我一直在阅读多篇文章,以使用生成的访问令牌获取SharePoint Online客户端上下文。所有这些都使用TokenHelper类来获取客户端上下文,如下所示:

ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(targetWeb, AccessToken);

我的问题是我们如何访问TokenHelper课程?我在参考Microsoft.SharePoint.Client版本16.1.0.0中找不到它。我们需要添加什么参考来访问这个类?

3 个答案:

答案 0 :(得分:4)

我能够从here得到答案。如果将来有人需要它,下面就是答案:

只需添加NuGet包AppForSharePointOnlineWebToolkit即可。它会将TokenHelper.csSharePointContext.cs文件添加到您的项目中。

答案 1 :(得分:0)

请在您的解决方案中安装以下NuGet包:

<强> - &GT; AppForSharePointWebToolkit

enter image description here

安装将添加以下文件&amp;您的解决方案的参考: enter image description here

了解更多信息: https://www.nuget.org/packages/AppForSharePointWebToolkit/

请注意:

  1. AppForSharePointWebToolkit 适用于SharePoint 2013
  2. 如果您正在使用SharePoint 2016或使用Visual Studio 2017,则必须安装 AppForSharePoint16WebToolkit

答案 2 :(得分:0)

只要使用 Visual Studio ,并且安装了Office developer ToolsSharePoint Server 2013 Client Components SDK,就不需要任何NuGet软件包或其他外部资源。您所指的forum thread

只需创建一个新项目,然后从已安装/ Visual C#/ Office / SharePoint /加载项配置单元中选择 SharePoint加载项项目模板。在项目向导的第一页上,选择提供商托管的选项(我认为这是默认选项),然后在第二页上,选择 SharePoint Online 与O365一起使用。 TokenHelper.cs将包含在 Visual Studio 生成的项目中。

有关更多详细信息,请参见这些教程:

相关问题