2014-12-29 2 views
-1

목록 항목 값을 업데이트하기 위해 다음 코드를 실행하려고합니다. "설정"목록 이름이 목록에있는 항목 우리가 코드를 사용하여 목록의 view 이름 값을 얻는 방법 1.웹 서비스 코드를 사용하여 공유 지점의 기존 목록 항목 값을 업데이트하십시오.

Main() 
{ 
     ListsSoapClient client = new ListsSoapClient();    
     client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; 
     client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 
     string strListName = "Settings";   
     client.Open();   

     XElement listData = client.GetList(strListName); 
     string listID = listData.Attribute("ID").Value; 
     string version = listData.Attribute("Version").Value; 
     // string version = listData.Attribute("View").Value; Doesnt work 





     // Method 1 : Make the call to SharePoint 
     var listItems = client.GetListItems(strListName, null, null, null, null, null, null); 
     List<XElement> results = listItems.Descendants().ToList(); 
     XElement updateItem = results[1]; 
     updateItem.SetAttributeValue("ows_Value", "value to update"); 
     client.UpdateListItems(strListName, updateItem); //Didnt work 

     // Method 2 : Make the call to SharePoint 
     string strBatch = "<Method ID='1' Cmd='Update'>" + 
         "<Field Name='ID'>1</Field>" + 
         "<Field Name='Title'>" + "999" + "</Field></Method>"; 
     XmlDocument xmlDoc = new System.Xml.XmlDocument(); 
     System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch"); 
     //elBatch.SetAttribute("OnError","Continue"); //Not mandatory ? 
     //elBatch.SetAttribute("ListVersion","1"); //Not mandatory ? 
     //elBatch.SetAttribute("ViewName", "00F85842-35AD-4AED-8DF7-0F903FB850BE"); is it mandatory ? 

     elBatch.InnerXml = strBatch; 
     client.UpdateListItems(strListName, XmlElementToXelement(elBatch)); //doesnt work 
     client.Close(); 
    } 

    public static XElement XmlElementToXelement(XmlElement e) 
    { 
     return XElement.Parse(e.OuterXml); 
    } 

의 인덱스를 데 무엇입니까? 왜 방법 2에서 필수가 아닙니다. Method2에서 목록 항목 제목은 값 999로 바뀌고 있습니다. 여기서 해당 목록 항목의 값을 업데이트하려고합니다.

방법 1의 끝에서 나는 아래 예외를 얻고 있습니다. 어떻게 수정합니까?

Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown. 

답변

0

때때로이 오류의 원인은 SOAP 동작의 헤더입니다. 업데이트를하려면 다음을 설정해야합니다. :

beforeSend : function (xhr) {xhr.setRequestHeader ("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"); 내가 셰어에서 업데이트를 보낼 수있는 다음과 같은 기능을 만들었습니다

는 목록 :

 var location = yoururl 
     var listName = yourlistname 
     var command = "Update" // "Update" or "New" 
     var fieldnames = ["ID","Title"]; //array with the fieldnames 
     var fieldvalues = [value1,value2]; //array with the values 

function sendupdates(location,listName,command,fieldnames,fieldvalues){ 
    var updatesvar; 
    for(x=0;x<fieldnames.length;x++){ 
    updatesvar = updatesvar + '<Field Name="'+fieldnames[x]+'">'+fieldvalues[x]+'</Field>' 
    } 

    var batchvar = '<Batch OnError="Continue" ListVersion="0"><Method ID="1" Cmd="'+command+'">'+updatesvar+'</Method></Batch>'; 

    var soapEnv = 
       '<?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>'+ 
       '<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'+ 
       '<listName>'+listName+'</listName>'+ 
       '<updates>'+batchvar+'</updates>'+ 
       '</UpdateListItems>'+ 
       '</soap:Body>'+ 
       '</soap:Envelope>'; 

     $.ajax({ 
       url: location+"/_vti_bin/Lists.asmx", 
       beforeSend: function(xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");}, 
       type: "POST", 
       dataType: "xml", 
       data: soapEnv, 
       complete: complete, 
       contentType: "text/xml; charset=\"utf-8\"" 
      }); 

}

관련 문제