从哪里为 SharePoint Online 中的客户端上下文使用 TokenHelper class?
From where to use TokenHelper class for client context in SharePoint Online?
我已经阅读了几篇文章,以使用生成的访问令牌获取 SharePoint Online 客户端上下文。它们都使用 TokenHelper
class 来获取客户端上下文,如下所示:
ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(targetWeb, AccessToken);
我的问题是我们如何访问 TokenHelper
class?我在参考 Microsoft.SharePoint.Client
版本 16.1.0.0 中找不到它。我们需要添加什么引用才能访问此 class?
我能够从 here 那里得到答案。以防以后有人需要,下面是答案:
只需添加 NuGet 包 AppForSharePointOnlineWebToolkit
。它会将 TokenHelper.cs
和 SharePointContext.cs
文件添加到您的项目中。
请在您的解决方案中安装以下 NuGet 包:
--> AppForSharePointWebToolkit
安装将向您的解决方案添加以下文件和参考:
更多信息:
https://www.nuget.org/packages/AppForSharePointWebToolkit/
请注意:
- AppForSharePointWebToolkit 适用于 SharePoint 2013
- 如果您正在使用 SharePoint 2016 或 Visual Studio 2017,则必须安装 AppForSharePoint16WebToolkit
只要您使用 Visual Studio 并且拥有您提到的 Office developer Tools and SharePoint Server 2013 Client Components SDK installed, just as written in the forum thread,您就不需要任何 NuGet 包或其他外部资源。
只需创建一个新项目,然后 select 来自 Installed / Visual C# / Office/SharePoint 的 SharePoint 加载项 项目模板/ 加载项 配置单元。在项目向导的第一页 select Provider-hosted 选项(我认为这是默认选项),在第二页 select SharePoint Online 如果您想使用 O365。 TokenHelper.cs
将包含在 Visual Studio.
生成的项目中
有关详细信息,请参阅这些教程:
我已经阅读了几篇文章,以使用生成的访问令牌获取 SharePoint Online 客户端上下文。它们都使用 TokenHelper
class 来获取客户端上下文,如下所示:
ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(targetWeb, AccessToken);
我的问题是我们如何访问 TokenHelper
class?我在参考 Microsoft.SharePoint.Client
版本 16.1.0.0 中找不到它。我们需要添加什么引用才能访问此 class?
我能够从 here 那里得到答案。以防以后有人需要,下面是答案:
只需添加 NuGet 包 AppForSharePointOnlineWebToolkit
。它会将 TokenHelper.cs
和 SharePointContext.cs
文件添加到您的项目中。
请在您的解决方案中安装以下 NuGet 包:
--> AppForSharePointWebToolkit
安装将向您的解决方案添加以下文件和参考:
更多信息: https://www.nuget.org/packages/AppForSharePointWebToolkit/
请注意:
- AppForSharePointWebToolkit 适用于 SharePoint 2013
- 如果您正在使用 SharePoint 2016 或 Visual Studio 2017,则必须安装 AppForSharePoint16WebToolkit
只要您使用 Visual Studio 并且拥有您提到的 Office developer Tools and SharePoint Server 2013 Client Components SDK installed, just as written in the forum thread,您就不需要任何 NuGet 包或其他外部资源。
只需创建一个新项目,然后 select 来自 Installed / Visual C# / Office/SharePoint 的 SharePoint 加载项 项目模板/ 加载项 配置单元。在项目向导的第一页 select Provider-hosted 选项(我认为这是默认选项),在第二页 select SharePoint Online 如果您想使用 O365。 TokenHelper.cs
将包含在 Visual Studio.
有关详细信息,请参阅这些教程: