简体   繁体   English

SharePoint Rest文档库

[英]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 . 适当地,这些属性被标记为webServerRelativeURLsiteServerRelativeURL 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的属性webAbsoluteURLsiteAbsoluteURL访问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.

相关问题 使用REST更新SharePoint文档库中的文件内容-javascript - update a file content in SharePoint document library with REST - javascript 如何使用rest在sharepoint文档库中展开lookupfield - How to expand a lookupfield in a sharepoint document library using rest SharePoint REST API 用于 Sharepoint 在线检索超过 5000 个项目的列表/文档库中的项目 - SharePoint REST API for Sharepoint online retrieving items from a list/document library which exceeds 5000 items 如何使用 REST API 作为托管应用程序从客户端上传和获取 SharePoint 文档库中的项目? - How to upload and GET the Items in the SharePoint Document Library from client side using REST API as a HOSTED APP? 通过 REST API 获取 SharePoint 文档库中链接项后面的 URL - Get the URL behind link items in SharePoint document library via REST API 共享点错误“通过REST根据内容类型添加空白项目时,“将项目添加到文档库,请使用SPFileCollection.Add()” - Sharepoint error 'To add an item to a document library, use SPFileCollection.Add()' when adding blank item based on content type via REST Sharepoint:将程序复制文件复制到另一个文档库 - Sharepoint: Programmatic Copy File to Another Document library Sharepoint文档库-使用javascript的标题文件名 - Sharepoint Document Library - Filename to title using javascript 使用JavaScript在SharePoint 2010文档库中创建文档的副本 - Create a copy of document in SharePoint 2010 document library using JavaScript 如何从 Sharepoint 文档库文件夹中检索文件 - How to retrieve files from Sharepoint Document library Folders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM