简体   繁体   English

使用REST更新SharePoint文档库中的文件内容-javascript

[英]update a file content in SharePoint document library with REST - javascript

I want to update a file in SharePoint document library with the following code. 我想使用以下代码更新SharePoint文档库中的文件。 As descriptions in: http://msdn.microsoft.com/en-us/library/office/dn450841(v=office.15).aspx#bk_FileRequestExamples http://msdn.microsoft.com/en-us/library/office/dn292553(v=office.15).aspx#Files 如以下说明中所述: http : //msdn.microsoft.com/zh-cn/library/office/dn450841( v = office.15) .aspx# bk_FileRequestExamples http://msdn.microsoft.com/zh-cn/library/办公室/ dn292553(v = office.15)的.aspx文件#

The executeAsync returns successful but the file isn't update! executeAsync返回成功,但文件未更新! Can anybody help!? 有人可以帮忙吗?

var spUrl = appWebUrl + "/_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('" + itemUrl + "')/$value?@target='" + hostWebUrl + "'";
    var executor = new SP.RequestExecutor(appWebUrl);
    executor.executeAsync(
    {
        url: spUrl,
        type: "POST",
        body: "Here is the new Body",
        headers: {
            "X-HTTP-Method": "PUT",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: readContents,
        error: errorHandler,
        state: "Update"
    });

In the add method it gives me the error message!!!! 在添加方法中,它给我错误信息!!

So I find out I should use "method" instead of "type" when I update. 所以我发现我在更新时应该使用“方法”而不是“类型”。

基于MSDN文档https://msdn.microsoft.com/zh-cn/library/office/dn735924.aspx#properties,您必须使用:URL,方法,标头,成功和错误

had the same problem. 有同样的问题。 changing 改变

body: "Here is the new Body", 

to

data: "Here is the new Body",

solved the issue for me 为我解决了这个问题

暂无
暂无

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

相关问题 SharePoint Rest文档库 - SharePoint Rest Document library 如何使用Javascript在Sharepoint 2007文档库中创建新文件 - How to create a new file in Sharepoint 2007 document library using Javascript Output SharePoint 文档库文件到 CSV 文件使用 Z686155AF75A60A0EDD3F6E9D80C9Z 文件 - Output SharePoint Document Library Files to CSV File Using JavaScript Sharepoint文档库-使用javascript的标题文件名 - Sharepoint Document Library - Filename to title using javascript 共享点错误“通过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 如何使用rest在sharepoint文档库中展开lookupfield - How to expand a lookupfield in a sharepoint document library using rest 使用JavaScript在SharePoint 2010文档库中创建文档的副本 - Create a copy of document in SharePoint 2010 document library using JavaScript 在SharePoint网站中,将javascript文件应用于创建的每个文档库的选项是什么? - Within a SharePoint site, what is are my options to apply a javascript file to every document library that is created? 使用CSOM / JavaScript的SharePoint 2013 HTML5 Javascript上传到文档库 - SharePoint 2013 HTML5 Javascript Upload to Document library with CSOM/JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM