Read TimeSheet Data using CSOM Project Online

Read TimeSheet Data using CSOM Project Online

Add actual Hours in TimeSheet using CSOM Project Online. In this post, you will learn to Read TimeSheet Data using CSOM Project Online. You will learn to Get actual hours, Planned hours, Task Start date, Task End date, Task Comment and Time period of the task. If you need to create Timesheet Create Timesheet in Project Server 2013. and how to get timesheet data using SQL query in Project server 2013 then follow my post Get Timesheet Project Server 2013. below is code to read Read TimeSheet Data using CSOM Project Online.

If you don’t know to add references in your solutions then follow the post below

Add  references in Solution

[AdSense-A]

public static void ReadTimeSheet()
        {
            try
            {
                using (ProjectContext ProjectCont = new ProjectContext(PWA))//PWA Url
                {
                    SecureString passWord2 = new SecureString();
                    foreach (char c in Passwords.ToCharArray()) passWord2.AppendChar(c);
                    ProjectCont.Credentials = new SharePointOnlineCredentials(UserName, passWord2);
                    ProjectCont.Load(ProjectCont.Projects);
                    ProjectCont.ExecuteQuery();

                    ProjectCont.Load(ProjectCont.TimeSheetPeriods, c => c.Where(p => p.Start <= DateTime.Now && p.End >= DateTime.Now).
                        IncludeWithDefaultProperties(p => p.TimeSheet,
                                                     p => p.TimeSheet.Lines.Where(l => l.LineClass == TimeSheetLineClass.StandardLine).
                        IncludeWithDefaultProperties(l => l.Assignment,
                                                           l => l.Assignment.Task,
                                                           l => l.Work)));
                    ProjectCont.ExecuteQuery();

                    var myPeriod = ProjectCont.TimeSheetPeriods.FirstOrDefault();

                    if (myPeriod == null)
                        throw new Exception("Create the periods");

                    foreach (var item in myPeriod.TimeSheet.Lines)
                    {
                        string ProjectName = item.ProjectName;
                        string TaskName = item.TaskName;

                        foreach (var work in item.Work)
                        {

                            string PlannedWork = work.PlannedWork;
                            string ActualWork = work.ActualWork;
                            DateTime StartDate = work.Start;
                            string TaskComment = work.Comment;
                        }

                    }
                }
            }
            catch (Exception ex)
            {
            }
        }

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!