- At First, you need add a web reference http://yourserver/yoursite/_vti_bin/lists.asmx. If you are not familiar with it, please notice something. Adding a web reference is difference between VS 2005 and 2008. In VS 2005, you just add it. In VS 2008, you right click Service Reference, then click Add Reference, then click Advance in the following dialog.
- In your code, please assign the site URL and Credential.
YourWebService.Lists myList = new ReferenceToWebService.Lists();
myList.Credentials = System.Net.CredentialCache.DefaultCredentials;
myList.Url = "http://yourserver/web/_vti_bin/lists.asmx";
There are two tips.One, using the LINQ to parse XML is very convenient. Two, please use the internal name for the field. Below is a sample code which I copy from MSDN.
XmlElement batch = doc.CreateElement("Batch");
batch.SetAttribute("OnError", "Continue");
batch.SetAttribute("ListVersion", "1");
batch.SetAttribute("ViewName", "{GUID of View, including braces}");
batch.InnerXml = "<Method ID='1' Cmd='New'>" +
"<Field Name='ID'>New</Field>" +
"<Field Name='Title'>Something</Field>" +
"<Field Name='SomeField'>Something Else</Field></Method>";
myList.UpdateListItems("{GUID of List, including braces}", batch);
No comments:
Post a Comment