I am getting items from a list using caml query. After that I need to export to excel by csom (c#). I dont want to use pnp .
-
That code isn't working,I am looking for better effective code.If you have any leads ,kindly let me know @GaneshSanapjijo– jijo2019-08-16 12:14:45 +00:00Commented Aug 16, 2019 at 12:14
-
I am getting this error on asking {"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."} If you have any clue kindly let me knowjijo– jijo2019-08-17 17:45:32 +00:00Commented Aug 17, 2019 at 17:45
Add a comment
|
1 Answer
"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."
This error means you will need to load listItems collection before accessing it, here is a csom code demo to export list item into csv file for your reference:
static void Main(string[] args)
{
string csvFilePath = @"c:\temp\myCSV.csv";
StringBuilder items = new StringBuilder();
ClientContext clientContext = new ClientContext("http://sp/sites/dev/");
List list = clientContext.Web.Lists.GetByTitle("CustomList");
CamlQuery caml = new CamlQuery();
ListItemCollection listItems = list.GetItems(caml);
clientContext.Load(list);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach (ListItem listItem in listItems)
{
items.Append(listItem.Id + ",");
items.Append(listItem.FieldValues["Name"]);
items.AppendLine();
}
System.IO.File.WriteAllText(csvFilePath, items.ToString());
}
-
Thanks a lot, but I need to save it in a sharepoint list,without downloading it in local.I need to save it in a sharepoint list.jijo– jijo2019-08-21 13:31:01 +00:00Commented Aug 21, 2019 at 13:31

