Blog

Programmatically create a task item and assign to a SharePoint group

Nov 17, 2012 Blogs | SharePoint
In this blog you will see how to create a task item and assign to a SharePoint group using SharePoint object model

In this blog you will see how to create a task item and assign the task to a SharePoint group using SharePoint object model.


 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

 

namespace Console

{

    class Program

    {

        static void Main(string[] args)

        {

            using (SPSite site = new SPSite(https://serverName.com/sites/TEST))

            {

                using (SPWeb web = site.OpenWeb())

                {

                    SPList list = web.Lists.TryGetList("Tasks");

                    if (list != null)

                    {

                        // get the SharePoint group

                        SPGroup group = web.Groups["Training Co-ordinator"];

 

                        // Create a new task item

                        SPListItem task = list.Items.Add();

                        SPFieldUserValue assignToGroup = new SPFieldUserValue(web, group.ID, group.Name);

                        task["AssignedTo"] = assignToGroup;

                        task["Title"] = "Testing";

                        task["Description"] = "Testing";                      

                        task.Update();

                    }

                }

            }

        }

    }

}

 

Vijai Anand

Vijai Anand has been working in IT industry for over 5 years. He holds Bachelor's degree in Electronics and Communication Engineering. Vijai write articles and blogs related to SharePoint 2013, S...

  • 3rank
  • 6M readers
  • 3times
COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs