SharePoint calls WebService operation list note

Source: Internet
Author: User

Brief Introduction: system integration is often required in the use of SharePoint. As a Sharepoint developer, we need to provide interfaces to other systems, the WebService provided by Sharepoint provides such a function. Let's take a look at it and use the WebService provided by Sharepoint to operate the list.

Steps:

1. First, create a consoleProgram, Add a WebService reference

Address http: // <site>/_ vti_bin/lists. asmx

<Site> the website address, including the port number.

2. Reference-right-click to add service reference (1)-advanced-add web reference-enter the WebService address in the URL field (2)

(Figure 1)

(Figure 2)

3. Get list information

Try

{

Webservices1.lists listservice = new getlisttest. webservices1.lists ();

Listservice. Credentials = system. net. credentialcache. defaultcredentials;

Xmlnode ndlists = listservice. getlist ("test"); // parameter list name, string type

Console. Write (ndlists. outerxml );

}

Catch (exception ex)

{

Console. Write (ex. Message );

}

4. Obtain the list information result

5. Obtain listitem Information

// obtain listitem Information

webservices1.lists listservice = new getlisttest. webservices1.lists ();

listservice. credentials = system. net. credentialcache. defaultcredentials;

xmldocument xmldoc = new system. XML. xmldocument ();

xmlnode ndquery = xmldoc. createnode (xmlnodetype. element, "query", "");

xmlnode ndviewfields = xmldoc. createnode (xmlnodetype. element, "viewfields", "");

xmlnode ndqueryoptions = xmldoc. createnode (xmlnodetype. element, "queryoptions", "");

ndqueryoptions. innerxml = ""; // query Settings

ndviewfields. innerxml = ""; // view Settings

ndquery. innerxml = ""; // caml statement

try

{

xmlnode ndlistitems = listservice. getlistitems ("test", null, ndquery, ndviewfields, "1", ndqueryoptions, null); // obtain the list content

console. write (ndlistitems. outerxml); // output the obtained XML content

}

catch (system. web. services. protocols. soapexception ex)

{

}

6. Obtain the listitem information result

7. Modify the listitem item

Webservices1.lists listservice = new webservices1.lists ();

Listservice. Credentials = system. net. credentialcache. defaultcredentials;

String strbatch = "<method id = '1' cmd = 'update'>" + // The cmd parameter, which is updated and includes new and delete

"<Field name = 'id'> 1 </field>" + // The field name is used as the field value.

"<Field name = 'title'> This has been modified </field> </method> ";

Xmldocument xmldoc = new system. xml. xmldocument ();

System. xml. xmlelement elbatch = xmldoc. createelement ("batch ");

Elbatch. innerxml = strbatch;

Xmlnode ndreturn = listservice. updatelistitems ("test", elbatch); // The first parameter is the list name.

Console. Write ("operation successful ");

8. The result after the listitem is modified.

8. The above are examples of WebService operations on the list. You can also refer to the example of Microsoft.CodeThe read information is XML, and then we can get the information we need in XML.

SDK address for lists: http://msdn.microsoft.com/zh-cn/library/websvclists.lists_methods (V = office.12). aspx

**************************************** **************************************

Author: Yu

Source: http://www.cnblogs.com/jianyus

The copyright of this article is shared by Yu and the blog Park. You are welcome to reprint it, but please indicate the source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.