码迷,mamicode.com
首页 > 其他好文 > 详细

share point 客户端模式 创建 list

时间:2017-10-08 22:34:03      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:share   param   title   opd   exe   北京市   stat   rip   div   

 /// <summary>
        /// 创建新的列表 list
        /// </summary>
        /// <param name="web"></param>
        /// <param name="context"></param>
        public static void CreateLsit(Web web, ClientContext context)
        {
            //表名
            string tableName = "Form11List";

            ListCreationInformation listCreationInfo = new ListCreationInformation();
            listCreationInfo.Title = tableName;
            listCreationInfo.TemplateType = (int)ListTemplateType.GenericList;
            List list_Info = web.Lists.Add(listCreationInfo);
            list_Info.Description = "New Description";
            // Add fields to the list.  
            Field field1 = list_Info.Fields.AddFieldAsXml(
            @"<Field Type=‘Choice‘  
            DisplayName=‘City‘  
            Format=‘Dropdown‘>  
            <Default>北京市</Default>  
            <CHOICES>  
            <CHOICE>上海市</CHOICE>  
            <CHOICE>深圳市</CHOICE>  
            </CHOICES>  
            </Field>",
            true, AddFieldOptions.DefaultValue);
            Field field2 = list_Info.Fields.AddFieldAsXml(
            @"<Field Type=‘Number‘  
            DisplayName=‘Name‘/>",
            true, AddFieldOptions.DefaultValue);

            Field field3 = list_Info.Fields.AddFieldAsXml(
            @"<Field Type=‘Number‘  
            DisplayName=‘Age‘/>",
            true, AddFieldOptions.DefaultValue);

            Field field4 = list_Info.Fields.AddFieldAsXml(
           @"<Field Type=‘Number‘  
            DisplayName=‘Desc‘/>",
           true, AddFieldOptions.DefaultValue);

            list_Info.Update();
            context.ExecuteQuery();

            List announcementsList = context.Web.Lists.GetByTitle(tableName);
            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            ListItem newItem = announcementsList.AddItem(itemCreateInfo);
            newItem["Title"] = "My New Item!";
            newItem["Name"] = "1";
            newItem["Age"] = "28";
            newItem["Desc"] = "1";
            newItem.Update();

            context.ExecuteQuery();
        }

 

share point 客户端模式 创建 list

标签:share   param   title   opd   exe   北京市   stat   rip   div   

原文地址:http://www.cnblogs.com/foreverfendou/p/7638616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!