In this post I’m going to show
how you can update the existing share point task programmatically. Here is the
sample code,
Private void UpdateTask(string ListNAme, string Title, string Body, string Reference, string Status DateTime StartDate, DateTime DueDate, string PercentComplete, string AssignedTo, string Priority, int Taskid){try{SPSite site = new SPSite(URL);using (SPWeb web = site.OpenWeb()){SPList list = web.Lists[ListNAme];SPListItem itemToUpdate = list.GetItemById(Taskid);itemToUpdate["Title"] = Title;itemToUpdate["Body"] = Body;itemToUpdate["Status"] = Status;itemToUpdate["StartDate"] = StartDate.ToString("MMMM dd, yyyy");itemToUpdate["DueDate"] = DueDate.ToString("MMMM dd, yyyy");itemToUpdate["PercentComplete"] = PercentComplete;itemToUpdate["Priority"] = Priority;if (AssignedTo != ""){SPUser user = web.EnsureUser(AssignedTo);itemToUpdate["AssignedTo"] = user;}else{itemToUpdate["AssignedTo"] = AssignedTo;}itemToUpdate.Update();MessageBox.Show("Task has successfully saved." + Environment.NewLine + ex.Message, "Message");}}catch (Exception ex){MessageBox.Show("Couldn't update the Task" + Environment.NewLine + ex.Message, "Message");}}
No comments:
Post a Comment