简体   繁体   中英

How to create new tasks in Microsoft Project Server 2013

我们正在Microsoft SharePoint 2013中使用Microsoft Project Server2013。是否可以通过CodeBehind中的C#从WebPart在项目中创建任务,例如?

I don't know if you can do a Webpart to create tasks but, via CSOM you can connect to your PS2013 Projects and create some tasks.

I will post you here a piece of code that could help you:

You must first "Check-Out" the project like this:

projContext.Load(projContext.Projects);
projContext.ExecuteQuery();

var proj = projContext.Projects.First(p => p.Name == "Project");
projContext.ExecuteQuery();

var draftProj = proj.CheckOut();

projContext.Load(draftProj.Tasks);
projContext.ExecuteQuery();

CreateNewTask(draftProj);

Then, you can call the method of create new task sending the "draft project"

private static void CreateNewTask(DraftProject draftProj)
{
    TaskCreationInformation nt = new TaskCreationInformation();

    nt.Name = "Task name";
    nt.Start = DateTime.Today;
    nt.Duration = "20d";
    nt.Id = Guid.NewGuid();

    draftProj.Tasks.Add(nt);
    projContext.Load(draftProj.Tasks);

    draftProj.Update();
    projContext.ExecuteQuery();

}

Hope that helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM