23 October 2009

Simple SharePoint Code Snippets

Here are few code snippets that are handy to use while creating a WebParts.

Added / Updating SharePoint List
osite =SPContext.Current.Site;
oweb = osite.OpenWeb();

oweb.AllowUnsafeUpdates = true;

SPList olist = oweb.Lists["LIST NAME"];

SPListItem newTask = olist.Items.Add();

newTask["Title"] = TextBox1.Text.ToString();

newTask["Comments"] = txtComments.Text.ToString();
newTask.Update();
lbstatus.Text = "Comments Added successfully";
txtComments.Text = "";

lbstatus.Visible = true;

oweb.AllowUnsafeUpdates = false;
oweb.Close();






No comments:

Post a Comment

Thanks for your valuable comments

Rate Now: