zoukankan      html  css  js  c++  java
  • sharepoint 2010 中操作List

    Sharepoint 内置了几种列表类型:

      

    复制代码

    publicenum 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>
    protectedvoid 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>
    privatebool 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>
    protectedvoid 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>
    protectedvoid 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>
    protectedvoid 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();
    }
    }
    复制代码

     原文地址http://www.cnblogs.com/zjz008/archive/2010/11/06/1870509.html

  • 相关阅读:
    采用重写tostring方法使ComboBox显示对象属性
    JavaScript中正则表达式test()、exec()、match() 方法
    高级软件工程实践总结作业
    用户使用调查报告
    Beta阶段置顶集合
    Beta冲刺阶段总结随笔
    Beta冲刺Day7
    Beta冲刺Day6
    Beta冲刺Day5
    Beta冲刺Day4
  • 原文地址:https://www.cnblogs.com/liubinurl/p/2553244.html
Copyright © 2011-2022 走看看