Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有img附件的SharePoint newListItem Soap_Javascript_Ajax_Cordova_Sharepoint_Soap - Fatal编程技术网

Javascript 带有img附件的SharePoint newListItem Soap

Javascript 带有img附件的SharePoint newListItem Soap,javascript,ajax,cordova,sharepoint,soap,Javascript,Ajax,Cordova,Sharepoint,Soap,我的Apache Cordova应用程序中有一个函数,可以在sharepoint列表中创建一个新的列表项,我想知道是否可以向这个新项目添加一个图像,这将作为sharepoint列表中的“附件”。我添加新项目的函数如下所示: function CreateItem(Title, Description) { var soapEnv = "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-inst

我的Apache Cordova应用程序中有一个函数,可以在sharepoint列表中创建一个新的列表项,我想知道是否可以向这个新项目添加一个图像,这将作为sharepoint列表中的“附件”。我添加新项目的函数如下所示:

function CreateItem(Title, Description) { 
var soapEnv =          
"<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +         
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +          
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +      
"<soapenv:Body>" +                           
"<UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" +     
"<listName>LISTNAME</listName>" +                
"<updates>" +                          
"<Batch OnError=\"Continue\">" +           
"<Method ID=\"1\" Cmd=\"New\">" +            
"<Field Name=\"ID\">New</Field>" +            
"<Field Name=\"Title\">" + Title + "</Field>" +
"<Field Name=\"Description\">" + Description + "</Field>" + 
"</Method>" +   
"</Batch>" +                         
"</updates>" +                        
"</UpdateListItems>" +               
"</soapenv:Body>" +                  
"</soapenv:Envelope>";               
$.ajax({     
url: "URL",
type: "POST",                           
dataType: "xml",                        
data: soapEnv,                         
beforeSend: function (xhr) {             
xhr.setRequestHeader("SOAPAction",           
"http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"); 
},                           
complete: processCreateResultSuccess,    
contentType: "text/xml; charset=\"utf-8\"",    
error: processCreateResultError             
});                    
}

该图像由Cordova应用程序拍摄,具有ID图像。有什么想法吗?

SharePoint:AddAttachment SOAP Web服务 可以,您可以使用SharePoint SOAP web services将图像附件上载到列表。但是,也有一些局限性

下面我的演示使用了。列出了所需的参数,可以针对您自己的环境进行修改。该演示只添加了一个文本文件附件,但它也适用于图像和其他文件类型。还与SP 2007-2013合作

限制是文件必须编码为base-64才能在SOAP信封中传输。在客户端,base-64文件编码不是一项简单的任务。我已经用这个对象完成了,但这只在现代浏览器IE10中可用。移动设备可能还有其他选择,但我还没有研究过。或者,您可以查看更新的


谢谢你,伙计,我已经做了一段时间了,你帮我澄清了这件事;
<html>
<body>

<script type='text/javascript'>

function addAttachment(  ) {

    var webUrl = '',                     // base url when list in sub site
        listName = 'CustomList',         // list name or guid 
        listItemID = '1',                // list item id
        fileName = 'HelloWorld.txt',     // file name 
        attachment = 'SGVsbG8gV29ybGQ=', // base-64 encode file data "Hello Word!"
        xhr, soap;

    soap = (
        '<?xml version="1.0" encoding="utf-8"?>'+
        '<soap:Envelope '+
                'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+
            'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '+
            'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
            '<soap:Body>'+
                '<AddAttachment xmlns="http://schemas.microsoft.com/sharepoint/soap/">'+
                    '<listName>' + listName + '</listName>'+
                    '<listItemID>' + listItemID + '</listItemID>'+
                    '<fileName>' + fileName + '</fileName>'+
                    '<attachment>' + attachment + '</attachment>'+
                '</AddAttachment>'+
            '</soap:Body>'+
        '</soap:Envelope>'
    );

    xhr = new XMLHttpRequest();
    xhr.open( 'POST', webUrl + '/_vti_bin/Lists.asmx', true );
    xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/sharepoint/soap/AddAttachment');
    xhr.onreadystatechange = function() {
        if (xhr.readyState != 4) return;
        // do something - returns file path or error message
        console.info( xhr.status + '\n' + xhr.responseText );
    }
    xhr.send( soap );

}

</script>
</body>
</html>