locked
Converting a sharepoint list item into XML file RRS feed

  • Question

  • All,

    I am trying to create an event handler that gets triggered when an item is added in the list. The functionality should be that whenever an item gets added in the list, the data that is being added needs to be converted into an XML file and and transferred to a remote web serever via a web service.

    I am confused at converting the data into XML file. Is there any API in Sharepoint that converts a list item in Sharepoint.

    Thanks.



    Monday, June 22, 2009 1:56 AM

Answers

  • SharePoint doesn't provide any API to do that. SPListItem which is the underlying type of a list item, has no public parameterless constructor so there is no possibility of XML serialization, meaning you would have to do that by yourself. It's not that difficult though. You should be able to create XML by looping through all the fields within an item, like:

    // instantiate XML here
    foreach (SPField f in listItem.Fields)
    {
      string value = listItem[f.Id] as string;
      // add value to XML here
    }
    w: http://blog.mastykarz.nl | t: @waldekm | c: http://imtech.codeplex.com | c: http://www.imtechvelocity.nl
    • Proposed as answer by RaghavanS Monday, June 22, 2009 5:47 AM
    • Marked as answer by Mike Walsh FIN Monday, June 22, 2009 6:23 AM
    Monday, June 22, 2009 4:29 AM

All replies

  • SharePoint doesn't provide any API to do that. SPListItem which is the underlying type of a list item, has no public parameterless constructor so there is no possibility of XML serialization, meaning you would have to do that by yourself. It's not that difficult though. You should be able to create XML by looping through all the fields within an item, like:

    // instantiate XML here
    foreach (SPField f in listItem.Fields)
    {
      string value = listItem[f.Id] as string;
      // add value to XML here
    }
    w: http://blog.mastykarz.nl | t: @waldekm | c: http://imtech.codeplex.com | c: http://www.imtechvelocity.nl
    • Proposed as answer by RaghavanS Monday, June 22, 2009 5:47 AM
    • Marked as answer by Mike Walsh FIN Monday, June 22, 2009 6:23 AM
    Monday, June 22, 2009 4:29 AM
  • Thanks Waldek. I understand what you are saying however i was looking for the API XmlDocument to create an Xml file and then add items in it. I just discovered the API and this seems to be an easy task. Thanks again for your response. You and your blogs and specially Imtech wsp file to create schema.xml of a list has made my life so easy.

     
    Monday, June 22, 2009 12:56 PM
  • Great to hear I could help. Good luck!
    w: http://blog.mastykarz.nl | t: @waldekm | c: http://imtech.codeplex.com | c: http://www.imtechvelocity.nl
    Tuesday, June 23, 2009 5:43 AM