Add / Update Tasks programmatically into the taskList in sharepoint - c#




Add Task Method

public bool AddTask(int ID, string RequestNumber, SPFieldUrlValue Link, SPFieldUserValueCollection AssignedTo)
{
 try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
               {
                   using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb())
                   {
                       oWebsite.AllowUnsafeUpdates = true;
                       SPListItemCollection SPLstItCol = spWeb.Lists["YourTaskName"].Items;
                     
   if (ID == 0)
                       {
                           SPListItem ListItem = SPLstItCol.Add();
                           ListItem["RequestNumber"] = RequestNumber;
                           ListItem["Assigned To"] = AssignedTo;
                           ListItem["Status0"] = Status;
                           ListItem["Link"] = Link;

                           ListItem.Update();
                       }
                       else
                       {
                           SPList listdoc = oWebsite.Lists["YourTaskName"];
                           SPListItem item = listdoc.GetItemById(ID);
                           item["Assigned To"] = AssignedTo;
                           item.Update();
                       }
                       oWebsite.AllowUnsafeUpdates = false;
                   }
               });
            }
            catch (Exception)
            {
                throw;
            }
            return true;
}

Comments

Popular posts from this blog

[SOLVED] The SharePoint Timer Service service terminated unexpectedly. Event ID : 7031

FIX : The password supplied with the username Domain\Username was not correct. Verify that it was entered correctly and try again.

FIX : stsadm is not recognized as an internal command