I slightly modified this example of how to use CSOM to display a list's current views.
I'm getting the following error: "Microsoft.SharePoint.Client.CollectionNotInitializedException: 'The collection 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 my code:
using (ClientContext cc = new ClientContext("https://demo.sharepoint.com/sites/SiteName"))
{
var passWord = new SecureString();
foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
cc.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);
Web oWeb = cc.Web;
List oList = oWeb.Lists.GetByTitle("Test List");
ViewCollection oViewCollection = oList.Views;
cc.Load(oWeb);
cc.Load(oList);
cc.Load(oViewCollection);
cc.ExecuteQuery();
Console.WriteLine(oWeb.Title);
Console.WriteLine(oList.Title);
foreach (View oneView in oViewCollection) //error occurs
{
Console.WriteLine(oneView.Title);
}
Console.ReadLine();
}
}
How can I resolve the error, so that I can loop through all of the view names and write them to the console?