[英]SharePoint Rest Document library
I am creating a custom page writing the HTML and javascript for a SharePoint site. 我正在创建一个自定义页面,为SharePoint网站编写HTML和JavaScript。 I would like to embed document libraries inside my custom html I am writing in SharePoint designer.
我想将文档库嵌入我在SharePoint Designer中编写的自定义html内。
I have nto found a way to easily embed document libraries in custom html but did stumble on some documentation for a rest api. 我已经找到了一种轻松地将文档库嵌入自定义html中的方法,但是却偶然发现了一些有关REST API的文档。 I figured I could use this and write my own ajax app in the html for users to navigate the document library.
我想我可以使用它并在html中编写自己的ajax应用程序供用户浏览文档库。
I am currently trying with this javascrip just to see if I can pull html or JSON for a document library contents: 我目前正在尝试使用此javascrip来查看是否可以为文档库内容提取html或JSON:
<script type="text/javascript">
var folderUrl = "x/x/x/testDocumentLibrary/Forms/AllItems.aspx";
var url = _spPageContextInfo.webServerRelativeUrl + "/_api/Web/GetFolderByServerRelativeUrl('" + folderUrl + "')?$expand=Folders,Files";
$.getJSON(url,function(data,status,xhr){
for(var i = 0; i < data.Files.length;i++){
console.log(data.Files[i].Name);
}
for(var i = 0; i < data.Folders.length;i++){
console.log(data.Folders[i].Name);
}
});
</script>
I am not sure if I am using the right url for the folderUrl
variable. 我不确定我是否为
folderUrl
变量使用了正确的URL。
In order to conduct some tests what is _spPageContextInfo.webServerRelativeURL
pulling? 为了进行一些测试,
_spPageContextInfo.webServerRelativeURL
是什么? I am trying to see if I can work backwards and create the URL manually first with out the SP function calls. 我正在尝试查看是否可以向后工作,并首先在没有SP函数调用的情况下手动创建URL。
The folderUrl
variable in your example code should end with the path to the library; 示例代码中的
folderUrl
变量应以库的路径结尾; everything up until /Forms/AllItems.aspx
, so /x/x/x/testDocumentLibrary
where /x/x/x/
is the server-relative path to the site on which the library resides. 直到
/Forms/AllItems.aspx
为止,因此/x/x/x/testDocumentLibrary
其中/x/x/x/
是库所在站点的服务器相对路径。
The _spPageContextInfo
object provides two variations of server-relative URL, one for the current site (called a "web" in SharePoint jargon) and one for the current site collection (called a "site" in SharePoint jargon). _spPageContextInfo
对象提供了两种相对于服务器的URL,一种用于当前网站(在SharePoint术语中称为“网站”),另一种用于当前网站集 (在SharePoint术语中称为“网站”)。 Appropriately, these properties are labeled webServerRelativeURL
and siteServerRelativeURL
. 适当地,这些属性被标记为
webServerRelativeURL
和siteServerRelativeURL
。 Both of these are server-relative, meaning that they exclude the first part of the domain name. 这两个都是相对于服务器的,这意味着它们排除了域名的第一部分。 (Instead of
https://constoso.com/sites/stackoverflow
they'll give you /sites/stackoverflow
.) (而不是
https://constoso.com/sites/stackoverflow
它们将为您提供/sites/stackoverflow
。)
For a REST call, you probably want the absolute URL, not the server-relative URL. 对于REST调用,您可能需要绝对URL,而不是服务器相对URL。 You can access the web and site absolute URLs through
_spPageContextInfo
's properties webAbsoluteURL
and siteAbsoluteURL
. 您可以通过
_spPageContextInfo
的属性webAbsoluteURL
和siteAbsoluteURL
访问Web和站点的绝对URL。
If the list/library you're accessing is on the current site where your REST is running, use the webAbsoluteURL
property. 如果要访问的列表/库位于运行REST的当前站点上,请使用
webAbsoluteURL
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.