views:

338

answers:

2

I am adding item into Sharepoint List from the Silverlight Application using Sharepoint' list.asmx web service. I need to know the ID of this newly created item. The UpdateListItemsCompleted's e.Result (XElement) is returned having the following XML fragment. How can I extract the ID of this item. I am not good in XLinq!

<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt; <Result ID="1,New"> <ErrorCode>0x00000000</ErrorCode> <ID /> <z:row ows_ID="4" ows_ContentTypeId="0x010046B4975C5FD8144EBBE658917B8CB92B00EAD628BF07FAF14DA2C983B981A32E7A" ows_ContentType="Item" ows_Title="My Test Entry From Silverlight" ows_Modified="2009-12-23 14:53:55" ows_Created="2009-12-23 14:53:55" ows_Author="3;#Khurram Aziz" ows_Editor="3;#Khurram Aziz" /> </Result> </Results>

A: 

From top of my head try this:

using System.Xml;

XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(@"<Results xmlns=""http://schemas.microsoft.com/sharepoint/soap/""&gt; <Result ID=""1,New""> <ErrorCode>0x00000000</ErrorCode> <ID /> <z:row ows_ID=""4"" ows_ContentTypeId=""0x010046B4975C5FD8144EBBE658917B8CB92B00EAD628BF07FAF14DA2C983B981A32E7A"" ows_ContentType=""Item"" ows_Title=""My Test Entry From Silverlight"" ows_Modified=""2009-12-23 14:53:55"" ows_Created=""2009-12-23 14:53:55"" ows_Author=""3;#Khurram Aziz"" ows_Editor=""3;#Khurram Aziz"" /> </Result> </Results>");
XmlNode xnode = xdoc.SelectSingleNode("//z:row[@ows_ID]"); //Select node that has attribute ows_ID
string idString = xnode.Attributes["ows_ID"].Value;
Janis Veinbergs
I am using Silverlight (v3); unfortunately XmlDocument, XmlNode and XPath (SelectSingleNode) are not available there :(
Khurram Aziz
XLinq should be available (XDocument / XElement) see how to use this here: http://forums.silverlight.net/forums/t/11702.aspx
Colin
A: 

Edit: I read the XML too hastily..

Try..

           e.Result.Elements()
                    .Where(c => c.Name.LocalName == "Result").First().Elements()
                        .Where(c => element.Name.LocalName == "row").First().Attribute("ows_ID").Value;
zincorp
e.Result.Element("z:row") is giving "The ':' character, hexadecimal value 0x3A, cannot be included in a name." XmlException!
Khurram Aziz
Yes; it worked and helped removed my nested GetEnumerator() / MoveNext() / Current code :)Just a small correction in Lambda...e.Result.Elements().Where(c => c.Name.LocalName == "Result").First().Elements().Where(c => element.Name.LocalName == "row").First().Attribute("ows_ID").Value;
Khurram Aziz