gpt4 book ai didi

c# - 从 SharePoint 站点访问文件

转载 作者:太空宇宙 更新时间:2023-11-03 23:41:47 27 4
gpt4 key购买 nike

我的要求是使用 C# 访问位于 SharePoint 团队网站中的 Excel 文件。我可以直接从网站上载和下载文件,我已经为此授予了权限。但是该站点由其他一些组维护,没有暴露任何服务。有什么方法可以使用 C# 访问文件。

最佳答案

当您无法直接访问 SharePoint 系统本身时,只要您的同事没有停用负责的服务应用程序,您仍然应该能够使用 SharePoint 的 REST 服务 API。

您可以找到使用 REST 和 SharePoint 2013 读取文件的文档 here .

要通过 C# 访问 REST,您可以使用如下代码:

HttpWebRequest endpointRequest =
(HttpWebRequest)HttpWebRequest.Create(
"http://<site url>/_api/web/getfilebyserverrelativeurl('/Shared Documents/filename.docx')");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.Headers.Add("Authorization",
"Bearer " + accessToken);
HttpWebResponse endpointResponse =
(HttpWebResponse)endpointRequest.GetResponse();

关于c# - 从 SharePoint 站点访问文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28806166/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com