sharepoint 客户端对象模型之日历操作
sharepoint 客户端对象模型对日历的添加和删除操作,完整代码
1 //实例化网站,获取上下文关系 2 ClientContext c = new ClientContext("http://spweb");
1 //身份验证 2 c.Credentials = new System.Net.NetworkCredential("用户名", "密码", "域");
1 //获取操作对象 2 Web web = c.Web;
string renyuan = “zhangshan,lisi”;
string[] rilirenyuan = new string[] { };
rilirenyuan = renyuan.Split(',');
//对日历的添加操作 ListCreationInformation listInfo = null; foreach (var item in rilirenyuan) { listInfo = new ListCreationInformation(); listInfo.Title = item; listInfo.TemplateType = (int)ListTemplateType.Events; listInfo.QuickLaunchOption = QuickLaunchOptions.Off; web.Lists.Add(listInfo); c.ExecuteQuery(); string msg = "http://spweb/_layouts/15/start.aspx#/Lists/" + item + "/calendar.aspx \r\n"; byte[] myByte = System.Text.Encoding.UTF8.GetBytes(msg); //输出日志记录 using (FileStream fsWrite = new FileStream(@"D:\1.txt", FileMode.Append)) { fsWrite.Write(myByte, 0, myByte.Length); }; Console.WriteLine(item); }
//对日历的删除操作 foreach (var item in rilirenyuan) { List oList = web.Lists.GetByTitle(item); oList.DeleteObject(); c.ExecuteQuery(); Console.WriteLine(item + "delete"); }