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 );
}
}
}