========================================================== ====
Using Microsoft. SharePoint;
Spweb site = spcontrol. getcontextweb (context );
Splistitemcollection items = site. Lists ["listname"]. items;
Splistitem item = items. Add ();
Item ["field_1"] = onevalue;
Item ["field_2"] = twovalue;
Item. Update ();
Delete Sharepoint list data
========================================================== =====
Using Microsoft. SharePoint;
Spweb site = spcontrol. getcontextweb (context );
Splistitemcollection items = site. Lists ["listname"]. items;
Items [0]. Delete ();
Upload a file to SharePoint
========================================================== =====
Using system. IO;
Using Microsoft. SharePoint;
If (htmlinputfile1.postedfile! = NULL)
{
Spweb site = new spsite (destinationurl). openweb ();
Stream stream = htmlinputfile1.postedfile. inputstream;
Byte [] buffer = new bytes [stream. Length];
Stream. Read (buffer, 0, (INT) stream. Length );
Stream. Close ();
Site. Files. Add (destinationurl, buffer );
}
Query records and update data
========================================================== ========
Using Microsoft. SharePoint;
Spweb web = new spsite ("http: // Nick"). openweb ("test"); // open website
Web. allowunsafeupdates = true;
Splist list = web. Lists ["listname"];
Spquery query = new spquery ();
Query. query = "<where>" +
"<And>" +
"<EQ> <fieldref name =/" filed_1/"/> <value type =/" text/"> test </value> </EQ>" +
"<EQ> <fieldref name =/" filed_2/"/> <value type =/" text/">" + (string) onevalue + "</value> </EQ>" +
"</And>" +
"<EQ> <fieldref name =/" filed_3/"/> <value type =/" text/">" + (string) twovalue + "</value> </EQ>" +
"</And>" +
"</Where> ";
Query. rowlimit = 10;
// Query
Splistitemcollection items = List. getitems (query );
Try
{
If (items. Count! = 0)
{
// Update Sharepoint list data
Foreach (splistitem list in listitems)
{
List ["filed_1"] = textbox1.text. tostring ();
List ["filed_2"] = textbox2.text. tostring ();
List ["filed_3"] = textbox3.text. tostring ();
Listitem. Update ();
}
}
Else
{// Add data records to SharePoint
Splistitem addlist = List. Items. Add ();
Addlist ["filed_1"] = textbox1.text. tostring ();
Addlist ["filed_2"] = textbox2.text. tostring ();
Addlist ["filed_3"] = textbox3.text. tostring ();
Addlist. Update ();
}
}
Catch
{
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1516166