SharePoint Web Service series: add, delete, and modify a list

Source: Internet
Author: User

When a heterogeneous application accesses a Sharepoint document library or list, the WebService method is no longer appropriate. A friend asked me how to control list items in SharePoint 3.0 in applications under DOTNET Framework 2003. Think about similar scenarios, so I wrote the following demo. The following code is successfully tested in vs2005.

Using system;
Using system. xml;
Using system. Collections. Generic;
Using system. text;

Namespace consoledemo
{
Class Program
{
Static void main (string [] ARGs)
{

Try
{
Test ();
}
Catch (exception ex)
{
Console. writeline (ex. Message );
}
Console. writeline ("end ");
Console. Read ();
}

Private Static void test ()
{
Labportal. Lists listservice = new consoledemo. labportal. Lists ();
Listservice. Credentials = system. net. credentialcache. defaultcredentials;

String strbatch = "<method id = '1' cmd = 'new'>" + //
// ID is the unique identifier of a method. If multiple methods exist, they are listed below.
// The cmd types include new, update, and delete. Add, delete, and update
"<Field name = 'id'> New </field>" + //
// ID is only a unique identifier when adding an operation. You can specify it as needed and it does not correspond to the actual
// ID of the listitem. However, the actual ID must be used to delete or update a record, because it is required to specify a unique record.
"<Field name = 'title'> SMF </field>" +
"</Method> ";
Xmldocument xmldoc = new xmldocument ();
Xmlelement elbatch = xmldoc. createelement ("batch ");
// The attribue under the batch element is optional.
Elbatch. setattribute ("onerror", "continue"); // specifies whether to return or continue the next step after an error occurs.
Elbatch. setattribute ("listversion", "1"); // specify the version of the List
Elbatch. setattribute ("viewname", "654446d3-8e70-4483-b2b6-f87329eac2d9"); // specify the guid of the list view for the operation
Elbatch. innerxml = strbatch;
Xmlnode ndreturn = listservice. updatelistitems ("contracts", elbatch); // Add a record to the contact list named contracts

Console. writeline (ndreturn. outerxml );
}
}
}

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.