Adding New List Items Using the Lists.asmx Web Service


    

You can lead a CAML to water, but…


 


The current MSDN documentation contains what I might call *adequate* coverage of the use of Web Services with Windows Sharepoint Services 2.0  In the case of simple operations, such as retrieving list items, the samples are more or less useful and can be adapted for use in a local environment with few challenges.  Other operations, however, are not particularly well-documented — especially those that involve the use of CAML (Collaborative Application Markup Language) XML Batches.  Anyone who has attempted to delve into the wacky world of CAML has certainly discovered that working in CAML is somewhat convoluted.


 


Additionally, the current documentation contains no sample for adding NEW list items to Windows SharePoint Services 2.0 lists using the Lists.asmx Web Service.  The docs do contain update samples for existing items, but the CAML/XML syntax required to add a new item is somewhat different, and not well outlined in the SPPTSDK. 


 


So, in response to a recent customer request along these lines, I put together a sample that creates a very simple item in an Events list.  This has the added bonus of covering the proper type required to add date/time values for an event.  This Web Service can be used, for example, to add items to a shared WSS events list linked to Outlook Calendars (through the UI). 


 


An example implementation might be an application used by employees to indicate when they will be out of the office.  A shared calendar could be setup in WSS, which end users could then link to Outlook 2003 clients (by using the Link to Outlook button in WSS).  A separate application could be created which would take employee out of office requests, compare them to the existing events to either grant or deny the request, and add the request to the shared calendar if granted.


 


The sample below happens to be in VB.NET, which is a rarity for me and for the SDK docs in general (both of which tend to prefer C#), and in this case was part of a Windows Application designed to demonstrate the task.  The sample assumes the inclusion of a Web Reference to the Lists.asmx Web Service, as well as a Windows Form with five (5) text boxes (four of which are single-line text boxes, and the fifth being a multi-line text box used for writing out operation results.  Text boxes 1-4 are used for user input, and cover (respectively), the URL of the WSS site, the name of the Events List, the Title of the new Item, and the Start Date of the new Event Item.  Obviously, the sample could be expanded/adapted to include more or less information.  I’m NOT getting into recurring Events in this sample, but wish you ALL the luck in the world if you want to go ahead and attempt to implement that functionality yourself.  🙂


 


=====


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


 


Me.Cursor = System.Windows.Forms.Cursors.WaitCursor


Me.TextBox5.Clear()


 


Dim sURL As String = Me.TextBox1.Text


Dim sList As String = Me.TextBox2.Text


Dim sTitle As String = Me.TextBox3.Text


Dim sDate As String = Me.TextBox4.Text


 


Dim sDisplay As String = Me.TextBox5.Text


 


Dim sBatch As String = “”


 


Dim oListWS As New AddEventItemWSVB.localhost.Lists


 


oListWS.Credentials = System.Net.CredentialCache.DefaultCredentials


 


If (oListWS.Url.EndsWith(“/”)) Then


     oListWS.Url = sURL.Concat(sURL, “_vti_bin/lists.asmx”)


Else


     oListWS.Url = sURL.Concat(sURL, “/_vti_bin/lists.asmx”)


End If


 


sBatch = “<Method ID=””1″” Cmd=””New””>”


sBatch += “<Field Name=””ID””>New</Field>”


sBatch += “<Field Name=””Title””>” + sTitle + “</Field>”


sBatch += “<Field Name=””EventDate””>” + sDate + “</Field>”


sBatch += “</Method>”


 


Dim xDoc As New System.Xml.XmlDocument


Dim xBatch As System.Xml.XmlElement = xDoc.CreateElement(“Batch”)


 


xBatch.SetAttribute(“OnError”, “Return”)


xBatch.InnerXml = sBatch


 


Me.TextBox5.Text += “Submitting batch: ” + vbCrLf + xBatch.OuterXml


 


Try


 


     Dim xReturn As System.Xml.XmlNode = oListWS.UpdateListItems(sList, xBatch)


     Me.TextBox5.Text += vbCrLf + “Return: ” + vbCrLf + xReturn.OuterXml


 


Catch ex As Exception


 


     Me.TextBox5.Text += vbCrLf + “Exception: ” + vbCrLf + ex.Message


 


End Try


 


Me.Cursor = System.Windows.Forms.Cursors.Default


 


End Sub


 


=====


 


Note that the Date field requires a UTC date/time following the format: yyyy-mm-ddThh:mm:ssZ.  For example, 3 PM on October 23, 2004 would be represented as: 2004-10-23T15:00:00Z.


 


A typical successful response from this operation (e.g., the text written out to the multi-line text box #5) is below, with some names/IDs removed to protect the guilty:


 


=====


 


Submitting batch:


<Batch OnError=”Return”><Method ID=”1″ Cmd=”New”><Field Name=”ID”>New</Field><Field Name=”Title”>My New Event</Field><Field Name=”EventDate”>2004-10-08T12:00:00Z</Field></Method></Batch>


Return:


<Results xmlns=”http://schemas.microsoft.com/sharepoint/soap/”><Result ID=”1,New”><ErrorCode>0x00000000</ErrorCode><ID /><z:row ows_ID=”15″ ows_Title=”My New Event” ows_Modified=”2004-10-08 13:31:58″ ows_Created=”2004-10-08 13:31:58″ ows_Author=”1;#<DOMAIN\username>” ows_Editor=”1;#<DOMAIN\username>” ows_owshiddenversion=”1″ ows_Attachments=”0″ ows__ModerationStatus=”0″ ows_LinkTitleNoMenu=”My New Event” ows_LinkTitle=”My New Event” ows_SelectTitle=”15″ ows_Order=”1500.00000000000″ ows_GUID=”{F9158A44-3F57-44C1-BD87-269673F987C6}” ows_EventDate=”2004-10-08 12:00:00″ ows_fRecurrence=”0″ ows_EventType=”0″ xmlns:z=”#RowsetSchema” /></Result></Results>


 


=====


 


Happy Eventing! 


 


-R

Comments (125)

  1. Bil Simser says:

    This is why I created my SharePoint wrappers. So I could pass native .NET datatypes to SharePoint and have them do what they need to (like UTC date formatting) and treat things like lists as real objects over the wire. Of course I still need to publish them but they help people access the web services without having to deal with CAML and ugly stuff like that.

  2. Clemens says:

    this works …
    <br>
    <br>But now I’m trying to create a new list. With the webservice [list.asmx] it is not going to work because there isn’t an option to attach an template to it, so you have to do it manually (that’s not going to work in or daily build process 😉 an other option is to use rpc calls I’ve tried the newlist command in url cmd=newlist etc and in c# code with the use of calm… still no result.
    <br>Can you post an example of that? What works 😉 just like the sample above?
    <br>
    <br>Thx Clemens
    <br>

  3. I recently wanted to use Sharepoint’s web services to manipulate a list on one of our WSS sites.&amp;nbsp;…

  4. Prashanthspark says:

    I want to Add a new items in Lists using Webservice

    rNode = list.UpdateListItems(listName, elBatch);

    Using this code for email lookup :

    XmlElement field6 = doc.CreateElement("Field");

    field6.SetAttribute("Name", "email");

    try

    {

    //field6.InnerText = "myemail@ea.com";

    field6.Value = "myemail@ea.com";

    // Probleme is here to select from lookup field

    }

    catch

    {

    field6.InnerText = "";

    }

    What is the error here?

  5. Gogi says:

    Emphysema is a chronic respiratory disease where there is over-inflation

  6. Gogi says:

    pulmicort. All about of pulmicort.

  7. Donna says:

    Today was a complete loss. I feel like a fog. I’ve just been hanging out doing nothing, but eh…

  8. Linda says:

    I’ve just been letting everything pass me by lately. I’ve more or less been doing nothing. Not much going on lately. I can’t be bothered with anything recently.

  9. Alise says:

    Not much on my mind recently. I haven’t gotten much done. What can I say? I haven’t been up to much these days, but such is life. I feel like a complete blank, but so it goes…)))

  10. Mikle says:

    Good site! Well.. i like design!

  11. Besid,Besid says:

    Very good project! <a href= http://www.debtconsolidation.newov.info >debt consolidation</a> <a href= http://www.badcreditloan.newov.info >bad credit loan</a>

  12. Qest,Qest says:

    Very nice resources!<a href= http://www.mortgagerefinancing.newov.info  >mortgage refinancing</a> <a href= http://www.autoinsurancequote.newoz.info >auto insurance quote</a>

  13. Milas says:

    Well…good news, i like your site, Happy new year! )))

  14. Berrip says:

    I just don’t have much to say recently, but whatever. I feel like a complete blank, not that it matters. I’ve just been letting everything happen without me lately.

    <a href=’http://web-hosting.blogpostworld.org/unlimited-web-hosting.html‘>unlimited web hosting</a>

    Good luck !

  15. Ocis,Ocis says:

    Very nice resources!<a href= http://betting.ggfix.com >betting</a> <a href= http://wagering.ggfix.com >wagering</a>

  16. Jonn says:

    Happy New Year! real good site!

  17. Victor says:

    real good site!

  18. Dingo says:

    real good news! good site, respect webmaster!

  19. Chuck says:

    I liked this site, it’s neat. Good job! Please visit my homepage too:

    <a href=  ></a> [url=][/url]

  20. Jak says:

    …good day! Congratulations on a great web site….))

  21. Jak says:

    You have very nice site! well,,, happy new Year!!!

    My site: http://www.onlinewebservice6.de/gastbuch.php?id=126942

  22. Lohness says:

    You have a good site! Real good html-code

  23. Ron says:

    Best site! Great! wow wow wow!

  24. videochatbox says:

    Hello people! Nice site! <a href=’http://hometown.aol.com/videochatbox‘>videochatbox</a>

  25. Kate,Kate says:

    You have made a good site <a href= http://docs.google.com/View?docid=df2wwh2p_7c7mc89 >Debt Consolidation</a> [url=http://docs.google.com/View?docid=df2wwh2p_7c7mc89]Debt Consolidation[/url]  Good-bye!

  26. Lawrence says:

    Very well! Your site is neat! Visit my sites, please:

    <a href= http://fm7.biz/0l6s >buy valium</a> [url=http://fm7.biz/0l6s]buy valium[/url]

  27. taxtipsf says:

    for free tax advice and information head over to [url=]http://www.taxtipsforum.co.uk[/url]

    for jobs in berkshire go to [url=]http://www.berkshirejobforum.com[/url]

  28. Good site. Thank you!,Good site. Thank you!

  29. Good site. Thank you!,Good site. Thank you!

  30. Good site. Thank you!,Good site. Thank you!

  31. Good site. Thank you!,Good site. Thank you!

  32. Good site. Thank you!,Good site. Thank you!

  33. Hello! Great site!,Hello! Great site!

  34. Linkin park says:

    Best my wishes to Admin. Plz look my site too:

    <a href=http://linkin-park.creablog.com>linkin”>http://linkin-park.creablog.com>linkin park concert ticket</a> | [url=http://linkin-park.creablog.com]linkin park concert ticket[/url] | http://linkin-park.creablog.com – linkin park concert ticket !  Thanks.  p.s. Linkin Park Concert Ticket

  35. Cool website! Good work. Good resources here. Best regards!

  36. Les Stockton says:

    Tried very similar code.  I’m new to SharePoint.  Got a good return string, I think, but didn’t see anything new in my list.

    What do you put for the list name?  In my case, mine was "Tasks".  Do I have to put in a full path, or just "Tasks"?

    I mean, there are several lists called Task on this server, so how does it know which one is mine?

    Here’s my return string:

    <Result ID="1,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/"><ErrorCode>0x00000000</ErrorCode><ID />

    <z:row ows_ID="4" ows_Title="Test2" ows_Modified="2007-03-06 14:36:35" ows_Created="2007-03-06 14:36:35"

    ows_Author="90;#Stockton, Walter" ows_Editor="90;#Stockton, Walter" ows_owshiddenversion="1"

    ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Test2" ows_LinkTitle="Test2"

    ows_SelectTitle="4" ows_Order="400.000000000000" ows_GUID="{1BA35FC7-A2EA-4B8A-8952-8DB13924CA1D}"

    ows_Priority="(2) Normal" ows_Status="Not Started" ows_StartDate="2007-03-06 14:36:35" xmlns:z="#RowsetSchema" /></Result>

  37. Young Jeezy says:

    Looks great! I found lots of intresting things here. I will visit your website again.

    http://jeezy.blogcu.com/ Young Jeezy

  38. Buy xenical says:

    I have already enjoy your website, and it is so nice and cool. I will visit your website again.

    <a href= http://xenicalonline.blogcu.com >Xenical</a>

    [url= http://xenicalonline.blogcu.com ]Xenixal[/url]

  39. Buy Zantac says:

    Looks great! I found lots of intresting things here. Many thanks. Nice site. Cheers!

  40. Buy Zantac says:

    Looks great! I found lots of intresting things here. Many thanks. Nice site. Cheers!

  41. Evista says:

    This is really fresh idea of the design of the site! I seldom met such in Internet. Good Work dude!

  42. Vanessa says:

    Respect you!Added to favorites!!Nice site!

    This is my site:

    http://babyslinghammock.blogspot.com

  43. Lucy! Please call me,Lucy! Please call me

  44. Guruchel says:

    Respect you!Added to favorites!!Nice site!

    buy Lamisil Oral

    http://wapurl.co.uk/?G2UJISD

  45. Lucy! Please call me,Lucy! Please call me

  46. Thanks for your great site!,Thanks for your great site!

  47. Celebrex says:

    Looks great! I found lots of intresting things here. Many thanks. Nice site. Cheers!

  48. Britneytgbgo says:

    Very nice! I have some LJ with news, check this out:

    <a href= http://iwantubadlyz.livejournal.com >Newest news</a>

    <a href= http://annakubat.livejournal.com >Check this out</a>

    <a href= http://jackie_simpson.livejournal.com >livejournal</a>

  49. Britneytgbgo says:

    Very nice! I have some LJ with news, check this out:

    <a href= http://iwantubadlyz.livejournal.com >Newest news</a>

    <a href= http://annakubat.livejournal.com >Check this out</a>

    <a href= http://jackie_simpson.livejournal.com >livejournal</a>

  50. Wried says:

    Very nice! I have some sites with news, check this out:

    <a href= http://nuhost.info >Politics news</a>

    <a href= http://susearch.info >Lastest news</a>

    <a href= yanasearch.info >Lifestyle news</a>

  51. Peter says:

    Added to favorites!!Respect you!

    This is my site:

    http://matress.iespana.es

    http://matress.iespana.es/doctor-approved-chiropractic-mattress.html

  52. Buy Evista says:

    This is really fresh idea of the design of the site! I seldom met such in Internet. I will visit your website again. Good Work dude!

  53. The Best Catalog.

    <a href=http://healthpiece.info/>Real”>http://healthpiece.info/>Real Catalog</a>[url=http://healthpiece.info/]The Real Catalog[/url]

  54. Hi Sam! Photos i send on e-mail.

    Green,Hi Sam! Photos i send on e-mail.

    Green

  55. Hi Sam! Photos i send on e-mail.

    Green,Hi Sam! Photos i send on e-mail.

    Green

  56. My compliments to a very nice website. I found lots of intresting things here.

  57. My compliments to a very nice website. I found lots of intresting things here.

  58. Buy Celebrex says:

    This is really fresh idea of the design of the site! I seldom met such in Internet. Good Work dude!

  59. Buy Celebrex says:

    I found lots of intresting things here. Please more updates.

  60. I found lots of intresting things here. Please more updates.

  61. Looks great! I found lots of intresting things here. Many thanks.

  62. Buy Celebrex says:

    Good Work dude! I will visit your website again.

  63. Buy Celebrex says:

    Frankly, the way things are right now, I’m not sure I’d want to play myself in my very own movie of the week.

  64. If you listen to the Matrix soundtrack on your Ipod, or perhaps a fun song, your life automatically becomes a movie.

  65. Buy Valium says:

    I have already enjoy your website, and it is so nice and cool. I will visit your website again. Thank you

  66. 4sg75fw76f says:

    t8tfu59cf6bausz3r <a href = http://www.764338.com/486862.html > a274mt1zk2h0xkq1 </a> [URL=http://www.141710.com/909422.html] br9e3vw7ece [/URL] 3uipj18axheiz

  67. Looks great! I found lots of intresting things here. Please more updates.

  68. Good Work dude! I will visit your website again.

  69. Buy Caverta says:

    Looks great! I found lots of intresting things here. Many thanks.

  70. Bush says:

    Dear Friend! Halo!

    http://cammoza.info

    <a herf=http://cammoza.info>cammoza.info&#36948;</a>

    <a herf=http://cammoza.info>cammoza.info&#36948;</a>

    My Regards!

  71. Buy Caverta says:

    Good site! It very impressive, easy to find helpful information. Keep up the great work.

  72. Buy Caverta says:

    Hi Webmaster! It was a pleasure to look through this site! there is a lot of new and fresh ideas)!Thank You

  73. Papayim says:

    <a href= http://xigozy.angelfire.com >a business decision</a> <a href= http://fatoso.angelfire.com >a 5 drop forwards</a> <a href= http://pohofu.angelfire.com >aaway messages</a> <a href= http://gukogi.angelfire.com >a change of pace lyric loose lip sink ship</a> <a href= http://wedovu.angelfire.com >a way to carry on again</a>

  74. Papayim says:

    <a href= http://xigozy.angelfire.com >a business decision</a> <a href= http://fatoso.angelfire.com >a 5 drop forwards</a> <a href= http://pohofu.angelfire.com >aaway messages</a> <a href= http://gukogi.angelfire.com >a change of pace lyric loose lip sink ship</a> <a href= http://wedovu.angelfire.com >a way to carry on again</a>

  75. Papayim says:

    <a href= http://xigozy.angelfire.com >a business decision</a> <a href= http://fatoso.angelfire.com >a 5 drop forwards</a> <a href= http://pohofu.angelfire.com >aaway messages</a> <a href= http://gukogi.angelfire.com >a change of pace lyric loose lip sink ship</a> <a href= http://wedovu.angelfire.com >a way to carry on again</a>

  76. Papaytu says:

    <a href= http://kehovi.angelfire.com >a recipe for salt and pepper prawns</a> <a href= http://galevi.angelfire.com >aa road watch dublin</a> <a href= http://tywysa.angelfire.com >a painted house book report</a> <a href= http://hetela.angelfire.com >aa arena dallas</a> <a href= http://gaxeku.angelfire.com >aardvark swimsuits</a>

  77. Papayxo says:

    <a href= http://kisepe.angelfire.com >a.m. best insurance</a> <a href= http://zohena.angelfire.com >a line mini skirt</a> <a href= http://gogyqu.angelfire.com >aardvarks to zebra</a> <a href= http://cogubu.angelfire.com >a1b</a> <a href= http://zuqaxe.angelfire.com >aaron carter photos 2005</a>

  78. Alex Taylor says:

    Site – very comprehensive and meticulous from all sides, its good! Just excellent website, I sure!

    <a href="http://caverta1.blogcu.com/3011326/">Caverta Generic</a>

  79. 6ozzo27gox says:

    3lbgonavon11dxe33 <a href = http://www.652682.com/800416.html > req73dk9n5 </a> [URL=http://www.522368.com/188173.html] 760yu8vodwvwyyxld [/URL] glo2k5hh

  80. – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]

  81. – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]

  82. – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]

  83. – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]

  84. Alex Taylor says:

    Site – very comprehensive and meticulous from all sides, its good! Just excellent website, I sure!

    http://caverta1.blogcu.com/ Caverta 100 mg

  85. – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]

  86. – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]

  87. – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]  – [URL= ]  [/URL]

  88. If you listen to the Matrix soundtrack on your Ipod, or perhaps a fun song, your life automatically becomes a movie.

  89. Luk says:

    You have very interesting site!

    Respect you!

    http://louisellipsehandbag.iespana.es

  90. Ken Johnson says:

    Wow — looks like someone needs to install a comment-spam filter

  91. Dane says:

    I liked how the thoughts and the insights of this article is well put together and well-written. Hope to see more of this soon.<a href="http://www.tutorandtrain.com/">clinical respiratory</a>