2

here I am trying to Access the ows_owshiddenversion i.e Hidden property of sharepoint calendar list as like below code.

 CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = "<View><Query><Where>" +
                                  "<DateRangesOverlap><FieldRef Name=\"EventDate\" />" +
                                  "<FieldRef Name=\"EndDate\" />" +
                                  "<FieldRef Name=\"RecurrenceID\"/>" +
                                  "<Value Type=\"DateTime\"><Now /></Value></DateRangesOverlap>" +
                                  "</Where></Query></View>";



                ListItemCollection collListItem = oList.GetItems(camlQuery);

                clientContext.Load(collListItem);

                clientContext.ExecuteQuery();

                foreach (ListItem oListItem in collListItem)
                {
                    var Title = oListItem["Title"] != null ? oListItem["Title"].ToString() : "";
                    var EventDate = oListItem["EventDate"] != null ? oListItem["EventDate"].ToString() : "";
                    var EndDate = oListItem["EndDate"] != null ? oListItem["EndDate"].ToString() : "";
                    var Location = oListItem["Location"] != null ? oListItem["Location"].ToString() : "";
                    var Description = oListItem["Description"] != null ? oListItem["Description"].ToString() : "";
                    var guid = oListItem["GUID"] != null ? ListItem["GUID"].ToString() : "";
                    var created = oListItem["Created"];
                    var modified = oListItem["Modified"];
                    bool Event = Convert.ToBoolean(oListItem["fAllDayEvent"]);
                    var recurrenceData = oListItem["RecurrenceData"];
                    var Number = (int)oListItem["ows_owshiddenversion"];
}

but when I reached to the

var Number = (int)oListItem["ows_owshiddenversion"];** it gives me a Exception as
"+      Hidden  'oListItem.ParentList.Hidden' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'   bool {Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException}
"

which I am unable to resolve.

1 Answer 1

2

The field's internal name is actually owshiddenversion. However, you'll likely need to add it as a ViewFields entry as well:

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where>" +
                    "<DateRangesOverlap><FieldRef Name=\"EventDate\" />" +
                    "<FieldRef Name=\"EndDate\" />" +
                    "<FieldRef Name=\"RecurrenceID\"/>" +
                    "<Value Type=\"DateTime\"><Now /></Value></DateRangesOverlap>" +
                    "</Where></Query>" +
                    "<ViewFields><FieldRef Name=\"Title\" />" +
                    "<FieldRef Name=\"EventDate\" />" +
                    "<FieldRef Name=\"EndDate\" />" +
                    "<FieldRef Name=\"Location\" />" +
                    "<FieldRef Name=\"Description\" />" +
                    "<FieldRef Name=\"GUID\" />" +
                    "<FieldRef Name=\"Created\" />" +
                    "<FieldRef Name=\"Modified\" />" +
                    "<FieldRef Name=\"fAllDayEvent\" />" +
                    "<FieldRef Name=\"RecurrenceData\" />" +
                    "<FieldRef Name=\"owshiddenversion\" />" +
                    "</ViewFields></View>";



ListItemCollection collListItem = oList.GetItems(camlQuery);

clientContext.Load(collListItem);

clientContext.ExecuteQuery();

foreach (ListItem oListItem in collListItem)
{
    var Title = oListItem["Title"] != null ? oListItem["Title"].ToString() : "";
    var EventDate = oListItem["EventDate"] != null ? oListItem["EventDate"].ToString() : "";
    var EndDate = oListItem["EndDate"] != null ? oListItem["EndDate"].ToString() : "";
    var Location = oListItem["Location"] != null ? oListItem["Location"].ToString() : "";
    var Description = oListItem["Description"] != null ? oListItem["Description"].ToString() : "";
    var guid = oListItem["GUID"] != null ? ListItem["GUID"].ToString() : "";
    var created = oListItem["Created"];
    var modified = oListItem["Modified"];
    bool Event = Convert.ToBoolean(oListItem["fAllDayEvent"]);
    var recurrenceData = oListItem["RecurrenceData"];
    var Number = (int)oListItem["owshiddenversion"];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.