怎么样在sharepoint 2010 中操作List的办法
2010-11-06 14:20:29 来源:WEB开发网核心提示:Sharepoint 内置了几种列表类型:public enum SPBaseType{ UnspecifiedBaseType = -1, GenericList = 0, DocumentLibrary = 1, Unused = 2, DiscussionBoard = 3,
Sharepoint 内置了几种列表类型:
public enum SPBaseType { UnspecifiedBaseType = -1, GenericList = 0, DocumentLibrary = 1, Unused = 2, DiscussionBoard = 3, Survey = 4, Issue = 5, }
/// <summary> /// 新建列表 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Click(object sender, EventArgs e) { using (SPSite site = new SPSite(requestUrl)) { using (SPWeb web = site.OpenWeb()) { SPList list = null; string listName = txtListName.Text.Trim(); // Check whether the list already exists try { list = web.Lists[listName]; } catch (ArgumentException) { } if (list == null) { Guid listId = web.Lists.Add(listName, "All our books",SPListTemplateType.GenericList); list = web.Lists[listId]; list.OnQuickLaunch = true; list.Update(); } } } }
/// <summary> /// 判断列表是否存在 /// </summary> /// <param name="listName"></param> /// <returns></returns> private bool IsListExist(string listName) { using (SPSite site = new SPSite(requestUrl)) { using (SPWeb web = site.OpenWeb()) { bool isExists = (from l in web.Lists.OfType<SPList>() where l.Title.Equals(listName) select l).Count() > 0; return isExists; } } }
/// <summary> /// 创建栏 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddField_Click(object sender, EventArgs e) { using (SPSite site = new SPSite(requestUrl)) { using (SPWeb web = site.OpenWeb()) { string listName = txtFieldList.Text.Trim(); SPList list = web.Lists[listName]; list.Fields.Add("ISBN", SPFieldType.Text, true); list.Fields.Add("LeadAuthor", SPFieldType.Text, true); list.Fields.Add("Price", SPFieldType.Currency, false); list.Update(); } } }
Tags:sharepoint List
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接