0

Please check the below code and suggest me a solution. The error says that Internal : Could not execute code stage because exception thrown by code stage: Object reference not set to an instance of an object on server. The object is associated with property ModifiedBy.

//List list = ctx.Web.Lists.GetByTitle(Folder1[0]);
Microsoft.SharePoint.Client.Folder folder = ctx.Web.GetFolderByServerRelativeUrl(SPFolder);


//Load List , Root Folder and Files
//ctx.Load(list);
//ctx.Load(list.RootFolder);
//ctx.Load(list.RootFolder.Folders);
//ctx.Load(list.RootFolder.Files);
ctx.Load(folder);
//ctx.Load(folder.Files);
ctx.Load(folder.Files,File=>File.IncludeWithDefaultProperties(_file=>_file.ModifiedBy.Email));

//Execute Query
ctx.ExecuteQuery();
                
//Get Query Result in File Collection
//FileCollection fcol = list.RootFolder.Files;
FileCollection fcol = folder.Files;

//Declare Normal Collection
DataTable dt=new DataTable();
dt.Columns.Add("File Name",typeof(string));
//dt.Columns.Add("Checked Out By User",typeof(string));
//dt.Columns.Add("Check In Comment",typeof(string));
dt.Columns.Add("Modified By",typeof(string));
dt.Columns.Add("Last Modified Time",typeof(DateTime));
dt.Columns.Add("Created Time",typeof(string));


foreach(Microsoft.SharePoint.Client.File f in fcol)
{
                DataRow dr = dt.NewRow();
                dr["File Name"]=f.Name;
                //dr["Checked Out By User"]=f.CheckedOutByUser.ToString();
                //dr["Check In Comment"]=f.CheckInComment.ToString();
                dr["Modified By"]=f.ModifiedBy.Email.ToString();
                dr["Last Modified Time"]=Convert.ToDateTime(f.TimeLastModified);
                dr["Created Time"]=f.TimeCreated.ToString();
                dt.Rows.Add(dr);
}

OutputCollection = dt;
  • 1
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Steve Oct 11 '22 at 09:04
  • Thanks for sharing the reference. But even this method didn't work. – Bhuvana Srija Ammanabrolu Oct 11 '22 at 09:37

0 Answers0