-1
我有下面的代碼,我試圖運行更新列表項值。 「設置」是列表名稱,此列表中的項目索引爲1.使用網絡服務代碼更新sharepoint中的現有列表項值
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);
}
如何使用代碼獲取列表的ViewName值?爲什麼它在方法2中不是強制性的。在方法2中,列表項標題將被替換爲值999.而我想更新該列表項的值。
在方法1結束時,我得到下面的異常。我該如何解決這個問題?
Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.