标签:one thread list item eric std console void let ack
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.SharePoint.Client; using System.IO;
#region 上传文档 public static void FileAdd() { List Item1 = Web.GetList("sites/tangkang/DocLib"); FileCreationInformation FileCf = new FileCreationInformation(); string ListName = @"C:\Users\dcadmin\Desktop\123 (3).txt"; FileStream Stream = new FileStream(ListName, FileMode.Open, FileAccess.Read); BinaryReader Reader = new BinaryReader(Stream); Byte[] Byteitem = Reader.ReadBytes((int)Stream.Length); Reader.Close(); Stream.Close(); FileCf.Content = Byteitem; FileCf.Overwrite = true; FileCf.Url = "test02.text"; Item1.RootFolder.Files.Add(FileCf); Context.ExecuteQuery(); Console.WriteLine("上传成功"); Console.ReadKey(); } #endregion
#region 删除列表项信息 /// <summary> /// 删除列表项信息 /// </summary> public static void ItemNewDelete() { ListItem list_item = Item.GetItemById(2); list_item.DeleteObject(); Context.ExecuteQuery(); Console.WriteLine("删除成功"); } #endregion
#region 修改列表项信息 /// <summary> /// 修改列表项信息 /// </summary> public static void ItemNewUpdate() { ListItem list_item = Item.GetItemById(1); list_item["FirstName"] = "少"; // Context.Load(list_item);如果需要使用list_item这个对象,一定要先Load //Context.ExecuteQuery();//Load完后必须执行这一步 list_item.Update(); Context.ExecuteQuery(); Console.WriteLine("修改成功"); } #endregion
#region 添加列表项信息 /// <summary> /// 添加列表项信息 /// </summary> public static void ItemNewAdd() { ListItemCreationInformation itemCreation = new ListItemCreationInformation(); ListItem newitem = Item.AddItem(itemCreation); newitem["Title"] = "唐"; newitem["FirstName"] = "康"; newitem.Update(); Context.ExecuteQuery(); Console.WriteLine("添加成功"); } #endregion
#region 查询列表项信息 /// <summary> /// 查询列表栏信息 /// </summary> public static void ItemNewSelect() { CamlQuery Query = new CamlQuery(); Query.ViewXml = ""; ListItemCollection ListItem = Item.GetItems(Query); Context.Load(ListItem); Context.ExecuteQuery(); foreach (ListItem item in ListItem) { Console.WriteLine(item["Title"]); } } #endregion
#region 添加列表栏信息 /// <summary> /// 添加列表栏信息 /// </summary> public static void ItemAdd() { Field field = Item.Fields.AddFieldAsXml("<Field DisplayName=‘籍贯‘ Type=‘Number‘ />", true, AddFieldOptions.DefaultValue); FieldNumber fieldNumber = Context.CastTo<FieldNumber>(field); fieldNumber.Update(); Context.ExecuteQuery(); Console.WriteLine("添加成功"); } #endregion
#region 删除列表 /// <summary> /// 删除列表 /// </summary> public static void ListDelete() { List list_Delete = Context.Web.Lists.GetByTitle("Test01");//根据名称来获取 list_Delete.DeleteObject(); Context.ExecuteQuery(); Console.WriteLine("删除成功"); } #endregion
#region 修改列表信息 /// <summary> /// 修改列表信息 /// </summary> public static void ListUpdate() { List list_Update = Context.Web.Lists.GetByTitle("Summer01");//根据名称来获取 list_Update.Title = "Test01"; list_Update.Update(); Context.ExecuteQuery(); Console.WriteLine("修改成功"); } #endregion
#region 添加列表 /// <summary> /// 添加列表 /// </summary> public static void ListAdd() { ListCreationInformation Creation = new ListCreationInformation(); Creation.Title = "Summer01"; Creation.TemplateType = (int)ListTemplateType.DocumentLibrary; List newlist = Web.Lists.Add(Creation); Context.ExecuteQuery();//与sharepoint通讯 Console.WriteLine("新建成功"); } #endregion
#region 查询列表信息 /// <summary> /// 查询列表信息 /// </summary> public static void ListSelect() { Context.Load(Web.Lists, lis => lis.Include(li => li.Title, li => li.ItemCount, list => list.Created)); Context.ExecuteQuery(); foreach (List lis in Web.Lists) { Console.WriteLine(lis.Title + lis.ItemCount); } } #endregion
#region 查询网站信息 /// <summary> /// 查询网站信息 /// </summary> public static void WebSelect() { Context.Load(Web); Context.ExecuteQuery();//与sharepoint通讯 Console.WriteLine(Web.Title); } #endregion
#region 修改网站信息 /// <summary> /// 修改网站信息 /// </summary> public static void WebUpdate() { Context.Load(Web, w => w.Title, wde => wde.Description); Web.Title = "Summer"; Web.Description = "Summer"; Web.Update(); Context.ExecuteQuery();//与sharepoint通讯 Console.WriteLine("修改成功"); } #endregion
#region 添加网站 /// <summary> /// 添加网站 /// </summary> public static void WebAdd() { WebCreationInformation Creation = new WebCreationInformation(); Creation.Url = "Summer"; Creation.Title = "Summer"; Creation.Description = "Summer"; Web newweb = Web.Webs.Add(Creation); Context.Load(newweb, w => w.Title, wde => wde.Description); Context.ExecuteQuery();//与sharepoint通讯 Console.WriteLine("新建成功"); } #endregion
标签:one thread list item eric std console void let ack
原文地址:http://www.cnblogs.com/summert/p/7217010.html