public static void CreateProjects(Guid ProjectUID, string ProjectName, string PlanStartDate)
{
string result = string.Empty;
string eptguid = string.Empty; //企业项目模板GUID
try
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
string url = "http://demo/pwa";
using (var projContext = new CSOM.ProjectContext(url))
{
CSOM.ProjectCreationInformation newProj = new CSOM.ProjectCreationInformation();
CSOM.JobState jobState = new CSOM.JobState();
//项目GUID
newProj.Id = ProjectUID;
//项目名称
newProj.Name = ProjectName;
//项目开始时间
newProj.Start = Convert.ToDateTime(PlanStartDate);
//获取企业项目类型GUID
newProj.EnterpriseProjectTypeId = new Guid(eptguid);
//将项目相关信息添加到发布对象中
CSOM.PublishedProject newPublishedProj = projContext.Projects.Add(newProj);
//项目更新成功,管理队列服务
CSOM.QueueJob qJob = projContext.Projects.Update();
jobState = projContext.WaitForQueue(qJob, 20);
if (jobState == CSOM.JobState.Success)
{
result = "创建成功";
}
}
});
}
catch (Exception ex)
{
result = ex.ToString();
}
}