I have a Sharepoint list which have columns like : CopmanyName, Add1, Add2 Country, State/Province. State/Province have a condition to enter only when country is as selected as America or Canada, So few records in SharePoint have this field(ows_State) as empty.
Now I am trying to get the records from SharePoint using webservices, CAML query, the problem that I am facing is that if the field (State/Provice) is empty then the CAML doesn’t get its information, in-fact the field name itself is not added in the z:row element of XML.
I have this field bound to a gridView on front-end (as Eval) and if element ows_State is not found in XML then it throws error.
Any suggestion would be much appreciated,
If nothing works then probably I’ll have to check and dynamically add this field.
var StateElement = doc.Element(rs + "data").Element(z + "row").Attribute("ows_State_x002f_Province");
if (StateElement == null)
{
doc.Element(rs + "data").Element(z + "row").Add(new XAttribute("ows_State_x002f_Province", " "));
}
I have had similar problem. The thing is, If your field is empty, CAML won’t return you that field in your XML.
The solution I made was to check XML for attribute’s existence, If it’s not there, add it manually.
Check this out :
http://naimishpandya.wordpress.com/2011/11/15/how-to-add-xml-attribute-to-an-existing-xml-node-in-c-c-sharp/
You can also achieve it through LINQ To XML.
http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/thread/be75108d-2265-41f0-8a22-f2ecc025cf53