Omar moussaid

Omar moussaid

  • NA
  • 22
  • 974

Retrieve TimeSheets of all users

Oct 31 2017 4:38 AM
I have created a simple console C# application that retrieves TimeSheets of the admin user used in the Sharepoint athentification, but what i want to do is to retrieve all users TimeSheets for a certain period (TimeSheetPeriods), any ideas about how you can do this? any sample code?
here is my code may be i forgot something :
 
  1. cntx.Load(cntx.Projects);  
  2. cntx.ExecuteQuery();  
  3. cntx.Load(cntx.TimeSheetPeriods, c => c.Where(p => p.Start <= DateTime.Now && p.End <= DateTime.Now).  
  4.     IncludeWithDefaultProperties(p => p.TimeSheet,  
  5.                                 p => p.TimeSheet.Lines.Where(l => l.LineClass == TimeSheetLineClass.StandardLine).  
  6.     IncludeWithDefaultProperties(l => l.Assignment,  
  7.                                 l => l.Assignment.Task,  
  8.                                 l => l.Work)));  
  9.                   
  10.   
  11. cntx.ExecuteQuery();  
  12. var myPeriod = cntx.TimeSheetPeriods.LastOrDefault();  
  13. if (myPeriod == null)  
  14.     throw new Exception("Please create the periods in your server settings");  
  15.                  
  16.   
  17. foreach (var line in myPeriod.TimeSheet.Lines)  
  18.     {  
  19.         Console.WriteLine("ProjectName : "+line.ProjectName);  
  20.         Console.WriteLine("TaskName : " + line.TaskName);  
  21.                       
  22.     foreach (var work in line.Work)  
  23.         {  
  24.             Console.WriteLine("PlannedWork----->" + work.PlannedWork);  
  25.   
  26.             Console.WriteLine("ActualWork----->" + work.ActualWork);  
  27.   
  28.             Console.WriteLine("StartDate----->" + work.Start);  
  29.   
  30.             Console.WriteLine("TaskComment----->" + work.Comment);  
  31.    
  32.          }  
  33.   
  34.     }   

Answers (1)