我的要求是使用 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/