文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>sharepoint 2010 中操作List

sharepoint 2010 中操作List

时间:2010-11-06  来源:i'm zjz

  


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();
                }
            }

 

 

 

 

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载