SharePoint List ListItem 增删改 新增 修改 删除
引用
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Import Namespace=”Microsoft.SharePoint.WebControls” %>
<%@ Import Namespace=”Microsoft.SharePoint.WebPartPages” %>
定义SPSite
SPSite site = new SPSite(hostUrl);
SPWeb rootweb = site.RootWeb;
修改时,这是必要的
rootweb.AllowUnsafeUpdates = true;
if (isListExist(rootweb.Lists, listTitle)==false)
SPList list = rootweb.Lists[listTitle];
新增
SPListItem thisitem = list.Items.Add();
thisitem["Title"] = TextBoxTitle.Text;
thisitem["cParentId"] = focus;
thisitem["cId"] = maxcId.ToString();
不要忘了
thisitem.Update();
删除
SPListItem item = getListItemBycId(list.Items, focus);
if (item != null)
item.Delete();
}
修改
SPListItem item = getListItemBycId(list.Items, focus);
if (item != null)
{
item["Title"] = TextBoxTitle.Text;
item["cUrl"] = “www.ceapet.com”;
item.Update();
}
源代码请参考页