SharePoint Calendar 解决方案

机缘

  1. 早些时候跟R谈过消息待办集成的方案,应该是有被接纳了。
  2. 但是他想借助SharePoint 的力量,先把日程安排先给搞上去。

功能说明

在这里插入图片描述

代码

查询

使用CAML查询语句进行查询,参考:https://docs.microsoft.com/zh-cn/sharepoint/dev/schema/query-schema

usingSPSite site = new SPSite("站点"){
   using (SPWeb web = site.OpenWeb())
   {
      SPList list = web.GetList("/Lists/List");
      SPQuery query = new SPQuery();
      query.Query = @"<Where><Contains><FieldRef Name='Title'/>" +
                            "<Value Type='Text'>SearchDataTest</Value></Contains></Where>";
      SPListItemCollection queryItems = list.GetItems(query);      
   }
}
声明CAML对象使用Add_Filter进行查询	
usingSPSite site = new SPSite("站点"){
   using (SPWeb web = site.OpenWeb())
   {
      SPList list = web.GetList("/Lists/List");
      CAML caml = new CAML();
      caml.Add_Filter("Add","Contains","Title","Text","SearchDataTest",true);          
      SPQuery query = new SPQuery();
      query.Query = caml.Where;
      SPListItemCollection queryItems = list.GetItems(query);           
   }
}

查询GetDataTable() 之后获取的数据参考

[{
	"ID": 1,
	"ContentType": "Event",
	"Title": "1",
	"Modified": "2022-05-31T17:00:30",
	"Created": "2022-05-31T17:00:30",
	"Author": "xxxx",
	"Editor": "xxxx",
	"_UIVersionString": "1.0",
	"Attachments": "0",
	"LinkTitleNoMenu": "1",
	"LinkTitle": "1",
	"DocIcon": null,
	"ItemChildCount": "0",
	"FolderChildCount": "0",
	"AppAuthor": "",
	"AppEditor": "",
	"Location": "1",
	"EventDate": "2022-04-25T18:00:00",
	"EndDate": "2022-04-25T19:00:00",
	"Description": null,
	"fAllDayEvent": "0",
	"fRecurrence": "0",
	"ParticipantsPicker": "",
	"Category": null,
	"FreeBusy": null,
	"Overbook": null
}]

新增

添加一个列表条目的方法非常简单,只需要调用SPListItemCollection.Add方法,该方法不需要参数,直接返回一个空的SPListItem对象,通过对该对象对各字段的内容进行修改,再调用Update方法,即可将该条目添加到该列表中。 var newitem = spList.Items.Add();

newitem["ContentType"] = "Event";
newitem["Title"] = "Jinzhan 请假" + i;
newitem["Modified"] = DateTime.Now;
newitem["Created"] = DateTime.Now;
newitem["EventDate"] = Convert.ToDateTime("2022-6-1 8:00:00");
newitem["EndDate"] = Convert.ToDateTime("2022-6-1 17:00:00");
newitem.Update();

删除

删除一个列表条目,有两种方法:

SPListItemCollection.DeleteById(int id)

通过列表条目的id来删除该条目;

SPListItemCollection.Delete(int index)	var spList = impersonatedWeb.Lists["tpv"]; 
spList.Items.Delete(2);//支持删除,参数为索引
spList..Items.DeleteItemById(2);//支持删除,参数为序号id

修改

比新增还简单,获取到这个对象之后,直接修改后,执行Update()

foreach (SPListItem item in spList.Items)
{
    item["Title"] = "Update By Jinzhan";
    item.Update();
}

Tips

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值