Tuesday, December 29, 2009

Create Custom Task in MOSS 2007

Guys..Below you can find the script to add custom Task in MOSS 2007 and assigned to a user.


protected void Button1_Click(object sender, EventArgs e)
{
try
{

using (SPSite site = new SPSite(http://YourServerName/YourSite))
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList TaskList = web.Lists["MyTasks"];

SPListItem NewTask = TaskList.Lists["MyTasks"].Items.Add();

NewTask["Priority"] = DropDownList2.SelectedValue;

NewTask["Title"] = TextBox1.Text;

NewTask["Description"] = TextBox3.Text;

NewTask["Assigned"] = DropDownList1.SelectedItem.Value;

NewTask.Update();
}
}

}
catch(Exception ex)
{
Response.Write(ex.Message);
}

}




Hope u find it useful...!!!!


Thanks,
Nitin Sharma