Let’s see how we can create new
share point task programmatically. Here is a sample code,
Private void CreateTask(string listName, string Title, string Body, string Reference, string Status, DateTime StartDate, DateTime DueDate, string PercentComplete, string AssignedTo, string Priority){try{SPSite site = new SPSite(URL);using (SPWeb web = site.OpenWeb()){SPList list = web.Lists[listName];SPListItem newItem = list.Items.Add();newItem["Title"] = Title;newItem["Body"] = Body;newItem["Status"] = Status;newItem["StartDate"] = StartDate.ToString("MMMM dd, yyyy");newItem["DueDate"] = DueDate.ToString("MMMM dd, yyyy");newItem["PercentComplete"] = PercentComplete;newItem["Priority"] = Priority;if (AssignedTo != ""){SPUser user = web.EnsureUser(AssignedTo);newItem["AssignedTo"] = user;}else{newItem["AssignedTo"] = AssignedTo;}newItem.Update();MessageBox.Show("Task has successfully saved." + Environment.NewLine + ex.Message, "Message");}}catch (Exception ex){MessageBox.Show("Couldn't create the Task" + Environment.NewLine + ex.Message, "Message");}}
No comments:
Post a Comment