views:

58

answers:

1

Hello,

I'm getting the data from sharepoint wbesite using

activeItemData = ws.GetListItems(listGUID, activeItemViewGUID, 
     qNode, vNode, rowLimit, null, "");

Here is what I got from the sharepoint its one record.

<**rs:data** ItemCount="1" ListItemCollectionPositionNext="Paged=TRUE&amp;p_ID=1" xmlns:rs="urn:schemas-microsoft-com:rowset">
   <**z:row** ows_ID="1" ows_Title="My RFC Title number one" ows_GUID="{A73B8E91-98BF-4CA7-8ADB-A3B933D6D8DA}" ows_Req_x0020_Number="112343" ows_Ends="2010-07-17 00:00:00" ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Start="2010-07-08 00:00:00" ows_owshiddenversion="13" ows_UniqueId="1;#{EA9E9C87-1B28-47DE-B7F4-DA4ADDF913F6}" ows_FSObjType="1;#0" ows_Created="2010-07-07 11:05:56" ows_Status="1. In-Work" ows_FileRef="1;#sites/PS/Lists/Change Control/1_.000" xmlns:z="#RowsetSchema" />
</rs:data>

Now to use LINQ to XML I change the object which hold this data from XMLDocument to XDocument by using

XDocument results = XDocument.Parse(activeItemData.OuterXml);

and the problem is that once I try to browse through the data to obtain ID and Title I got the error: Object reference not set to an instance of an object.

Here is the piece of code which I'm trying to use to get those fields:

 var items = from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
       select new
           {
               Title = item.Attribute("Title").Value,
               Id = item.Attribute("ID").Value 
           };

Seems that item is unable to locate this XName element

Thanks

A: 

Hi there.

Try:

 var items = from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
       select new
           {
               Title = item.Attribute("ows_Title").Value,
               Id = item.Attribute("ows_ID").Value 
           };

If you look at the row element:

<z:row ows_ID="1" ows_Title="My R.....

you were missing ows_ from the attribute name.

Cheers. Jas.

Jason Evans