I am trying to create a Windows Form for populating the information from SharePoint List into Windows Form. However, when I am trying to fetch the item from the list, it throws me an error message
An unhandled exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException' occurred in Microsoft.SharePoint.Client.dll Additional information: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."
Here is the code for the same.
private void btn_populatecontainer_Click(object sender, EventArgs e)
{
var authManager = new AuthenticationManager();
ClientContext overviewlistClientcontext = authManager.GetWebLoginClientContext("Tenant URL");
var tenant = new Tenant(overviewlistClientcontext);
var siteProperties = tenant.GetSiteByUrl("SiteCollectionURL");
Web web = siteProperties.RootWeb;
List olist = web.Lists.GetByTitle("SiteOverviewList");
overviewlistClientcontext.Load(siteProperties);
overviewlistClientcontext.ExecuteQuery();
ListItemCollectionPosition position = null;
var page = 1;
do
{
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='Recursive'><RowLimit>4000</RowLimit><Query><Where><Eq><FieldRef Name='Site URL'/><Value Type='Text'>" + txtSite.Text + "</Value></Eq></Where></Query></View>";
camlQuery.ListItemCollectionPosition = position;
ListItemCollection listItems = olist.GetItems(camlQuery);
overviewlistClientcontext.Load(listItems);
overviewlistClientcontext.ExecuteQuery();
position = listItems.ListItemCollectionPosition;
DataTable dataTable = new DataTable();
DataRow dr;
DataColumn dc = new DataColumn("Site Owner");
dc.DataType = Type.GetType("System.String");
dataTable.Columns.Add(dc);
foreach (var listItem in listItems)
{
dr = dataTable.NewRow();
dr["Site Owner"] = listItem["Site Owner"];
dataTable.Rows.Add(dr);
}
OverViewListGrid.DataSource = dataTable;
OverViewListGrid.DataBindings
page++;*/
}
while (position != null);
}
}
}
I have debugged the code and it fails when it tries to execute query after fetching from Caml Query.
- When CamlQuery gets executed, it doesn't work at all.
- However, for the testing purpose, I have tried to fetch other columns and the code works if I try to fetch Title/Id Column directly using inbuilt functions (i.e.
GetItembyID
). - But even the second steps won't work if i use another column from the same list.
Can anyone help me with this?