怎么样在sharepoint 2010 中操作List的办法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么样在sharepoint 2010 中操作List的办法相关的知识,希望对你有一定的参考价值。

参考技术A 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();




/// <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.Delete("Price"); //删除栏

//list.Update();




/// <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["标题"].Title = "Title";
//list.Fields["标题"].Update();

//list.Update();




using (SPSite site = new SPSite(requestUrl))

using (SPWeb web = site.OpenWeb())

SPList bookList = web.Lists["Books"];
SPListItem item = bookList.Items.Add();
item["Title"] = "流氓是怎么炼成的";
item["ISBN"] = "12345";
item["LeadAuthor"] = "abc";
item.Update();

本回答被提问者和网友采纳

以上是关于怎么样在sharepoint 2010 中操作List的办法的主要内容,如果未能解决你的问题,请参考以下文章

用microsoft sharepoint designer2010怎么做网站? 谢谢

关于sharepoint 2010的问题

Sharepoint 2010添加,编辑,删除表单替换为自定义可视Web部件

SharePoint 2010 权限管理

sharepoint 2010 的search功能怎么不能使用呢?

SharePoint 2010自定义操作