简体   繁体   English

为什么我的 C# 在 SharePoint 上找不到任何列表?

[英]Why can't my C# find any lists on SharePoint?

I'm trying to create a folder on an Online SharePoint with the site url https://example.sharepoint.com/MySite我正在尝试使用站点 url https://example.sharepoint.com/MySite在 Online SharePoint 上创建一个文件夹

I really don't care anything about SharePoint lists, but I can't find any information towards a SharePoint API which hides this implementation detail from the consumer, nor any documentation which anticipates my needs well enough to tell me what I need to do, so I am struggling to work with the Lists.我真的不关心 SharePoint 列表,但我找不到任何有关 SharePoint API 的信息,该 API 向消费者隐藏了此实现细节,也找不到任何文档可以很好地预测我的需求以告诉我我需要做什么,所以我正在努力处理列表。

At present, I just want to simply list whatever lists exist on my site.目前,我只想简单地列出我网站上存在的任何列表。 My site has some minimalistic content, so I expect in a world were everything has lists, there should be some lists involved and I should be able to somehow list them.我的网站有一些简约的内容,所以我希望在一个世界上一切都有列表,应该有一些列表涉及,我应该能够以某种方式列出它们。

I have the following code:我有以下代码:

            using (ClientContext context = _authenticationManager.GetContext())
            {
                Web web = context.Web;
                context.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.Id));
                context.ExecuteQuery();

                foreach (List list in web.Lists)
                {
                    _logger.LogInformation(list.Title);
                }
            }

I've been able to use the debugger and the console to confirm the AuthenticationManager is successfully generating an authentication token.我已经能够使用调试器和控制台来确认 AuthenticationManager 已成功生成身份验证令牌。

When the code executes, context.ExecuteQuery();代码执行时, context.ExecuteQuery(); results in the following error:导致以下错误:

[14:49:48 INF] Successfully requested new access token resource example.sharepoint.com for user someuser@somemail.foo <s:SharepointOrderContractExtractor.Clients.AuthenticationManager> [14:49:48 ERR] An unhandled exception has occurred while executing the request. [14:49:48 INF] 成功为用户 someuser@somemail.foo <s:SharepointOrderContractExtractor.Clients.AuthenticationManager> 请求新的访问令牌资源 example.sharepoint.com [14:49:48 ERR] 执行时发生未处理的异常请求。 <s:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware> System.Net.WebException: The remote server returned an error: (404) Not Found. <s:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware> System.Net.WebException:远程服务器返回错误:(404) 未找到。 at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at SharePointOrderContractExtractor.Clients.Client.CreateFolder(String folderName) in C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Clients\\Sharepoint\\Client.cs:line 34 at SharePointOrderContractExtractor.Services.SharePointService.CreateDestination(List 1 orderNumbers) in C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Services\\SharepointService.cs:line 128 at SharePointOrderContractExtractor.Services.SharePointService.CollectForAsync(List 1 orderNumbers) in C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Services\\Sharep在 System.Net.HttpWebRequest.GetResponse() 在 Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() 在 Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) 在 Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() 在 Microsoft .SharePoint.Client.ClientRuntimeContext.ExecuteQuery() 在 Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() 在 SharePointOrderContractExtractor.Clients.Client.CreateFolder(String folderName) 在 C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Clients\\Sharepoint\\Client。 cs:line 34 at SharePointOrderContractExtractor.Services.SharePointService.CreateDestination(List 1 orderNumbers) in C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Services\\SharepointService.cs:line 128 at SharePointOrderContractExtractor.Services.SharePointService.CollectForAsync(List ) :\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Services\\Sharep ointService.cs:line 95 at SharePointOrderContractExtractor.Services.SharePointService.FetchContractsAsync(FileUploadModel uploadModel) in C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Services\\SharepointService.cs:line 51 at SharePointOrderContractExtractor.Controllers.V1_0.SharePointController.Upload(FileUploadModel uploadModel) in C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Controllers\\V1_0\\SharepointController.cs:line 48 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted ointService.cs:line 95 at SharePointOrderContractExtractor.Services.SharePointService.FetchContractsAsync(FileUploadModel uploadModel) in C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Services\\SharepointService.cs:line 51 at SharePointOrderContractFileExtractor.VetchContractsAsync(FileUploadModel uploadModel)在 C:\\projects\\SharepointOrderContractExtractor\\SharepointOrderContractExtractor\\Controllers\\V1_0\\SharepointController.cs:line 48 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor controller, executor) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean Completed ) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Authorization.A ) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) 在 Microsoft.AspNetCore.Mvc.Infrastructure .ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, TaskScope lastTask, State next,范围、对象状态、布尔值 isCompleted) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker) 在 Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogbuckger logger) at Swashle .AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) 在 Microsoft.AspNetCore.Authorization.A uthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) uthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(Context)

What am I missing and/or doing wrong?我错过了什么和/或做错了什么? How can I correct this?我该如何纠正?

With thanks to @arconaut for his question in the comments:感谢@arconaut 在评论中提出的问题:

It seems the Authentication Manager only uses the domain, not the full URL in order to authenticate.身份验证管理器似乎只使用域,而不是完整的 URL 来进行身份验证。

While my site URL was set to https://example.sharepoint.com/MySite , it should have been https://example.sharepoint.com/sites/MySite .虽然我的网站 URL 设置为https://example.sharepoint.com/MySite ,但它应该是https://example.sharepoint.com/sites/MySite

(I think I dropped "sites" from the configuration while trying to follow some documentation which may not have matched my version of Salesforce.) (我想我在尝试遵循一些可能与我的 Salesforce 版本不匹配的文档时从配置中删除了“站点”。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM