How to created task in Sharepoint Project Server
Song Nghia - Technical Consultant
private void createTask_Click(object sender, EventArgs e) { // create PWA context projContext = new ProjectContext("http://sharepoint.votivasoft.com:81/PWA/"); // Access with default logged in credentials projContext.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; try { projContext.Load(projContext.Projects); projContext.ExecuteQuery(); // pass project GUID in place of combo box selection PublishedProject pubProject = projContext.Projects.GetByGuid(Guid.Parse(comboProjects.SelectedValue.ToString())); projContext.Load(pubProject); var job = projContext.Projects.Update(); projContext.ExecuteQuery(); DraftProject projectDraft = pubProject.CheckOut(); TaskCreationInformation taskCreation = new TaskCreationInformation(); taskCreation.Name = txtTaskName.Text; taskCreation.Start = dateTimeStart.Value; taskCreation.Finish = dateTimeFinish.Value; taskCreation.Id = Guid.NewGuid(); taskCreation.Duration = txtDuration.Text; taskCreation.IsManual = true; projectDraft.Tasks.Add(taskCreation); projectDraft.Update(); projectDraft.Publish(true); if (WaitForJob(projContext, job)) { //label1.Text = "Task Created"; } else { label1.Text = "Task failed"; } projectDraft.CheckIn(true); projContext.ExecuteQuery(); } catch (Exception ex) { } }