-1

This question already has an answer here:

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 .

marked as duplicate by Gaurravs, Ganesh Sanap, MHeld, Aakash Maurya, Waqas Sarwar MVP Aug 19 at 13:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • That code isn't working,I am looking for better effective code.If you have any leads ,kindly let me know @GaneshSanap – jijo Aug 16 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 know – jijo Aug 17 at 17:45
0

"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());
        }

enter image description here

enter image description here

  • 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 Aug 21 at 13:31

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