How we do it:
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb
web = site.OpenWeb())
{
web.AllowUnsafeUpdates
= true;
SPList list = web.Lists.TryGetList("TestExtensionList");
SPListItem item = list.Items.Add();
item[SPBuiltInFieldId.Title] = TextBox1.Text.Trim();
item.Update();
web.AllowUnsafeUpdates
= false;
}
}
How we can do it:
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb
web = site.OpenWeb())
{
web.DoUnsafeUpdate(delegate()
{
SPList list = web.Lists.TryGetList("TestExtensionList");
SPListItem item = list.Items.Add();
item[SPBuiltInFieldId.Title] = TextBox1.Text.Trim();
item.Update();
});
}
}