Object reference not set to an instance of an object on server. The object is associated with property "ModifiedBy"

227 views Asked by At

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;
0

There are 0 answers