简体   繁体   English

日历 CAML 查询,获取当月事件

[英]Calendar CAML Query, get current month event

May I ask about how can I get the current month event from Calendar?请问如何从日历中获取当月活动?

Here with my Source code.这里有我的源代码。

ClientContext clientContext = new ClientContext("https://intra.aspac.XXX.com/sites/sg");
Guid guid = new Guid("1F62FC88-XXXX-XXXX-XXXX-091D3023A99F");
List list = clientContext.Web.Lists.GetById(guid);
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";
ListItemCollection items = list.GetItems(query);

clientContext.Load(list);
clientContext.Load(items);

clientContext.ExecuteQuery();

foreach (ListItem item in items)
{
   //Console.WriteLine(item.Id + " - " + item["Name"]);
     Label1.Text = " - " + item["Title"] + item["Description"] + item["EventDate"] + "/"+item.Id;
}

You can get current month event using CAML Query like this:您可以使用 CAML 查询获取当前月份的事件,如下所示:

using System;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Utilities;


namespace ConsoleApplication7
{
    class Class1
    {
        static void Main(string[] args)
        {
            DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            string firstDayValue = SPUtility.CreateISO8601DateTimeFromSystemDateTime(firstDay);
            string firstDayValueplus1Month = SPUtility.CreateISO8601DateTimeFromSystemDateTime(firstDay.AddMonths(1));

            ClientContext clientContext = new ClientContext("http://sp/sites/dev");
            Guid guid = new Guid("d62d9bae-8dce-4aa6-aedb-73e82cd1415b");
            List list = clientContext.Web.Lists.GetById(guid);
            CamlQuery query = new CamlQuery();
            query.ViewXml = "<View><Query><Where><And><Geq><FieldRef Name='EventDate' /><Value Type='DateTime'>" + firstDayValue +
                        "</Value></Geq><Leq><FieldRef Name='EndDate' /><Value Type='DateTime'>" + firstDayValueplus1Month +
                        "</Value></Leq></And></Where>"+"</Query></View>";
           
            ListItemCollection items = list.GetItems(query);

            clientContext.Load(list);
            clientContext.Load(items);

            clientContext.ExecuteQuery();

            foreach (ListItem item in items)
            {

            }
            
        }
    }
}

You will facing the Problem with rendering list RSS feed in Firefox您将面临在 Firefox 中呈现列表 RSS 提要的问题

In order to fix this issue you may use the following workaround for Sharepoint on-premise: create ashx handler, put it to /Layouts subfolder, code of the handler will send internal http request to OTB /_layouts/15/listfeed.aspx?List={listId} url, then remove enclosure tag via Regex and return final result to the response (ie implement kind of proxy for OTB RSS feed):为了解决这个问题,您可以对 Sharepoint 本地使用以下解决方法:创建 ashx 处理程序,将其放入 /Layouts 子文件夹,处理程序的代码会将内部 http 请求发送到 OTB /_layouts/15/listfeed.aspx?List ={listId} url,然后通过 Regex 删除附件标签并将最终结果返回给响应(即为 OTB RSS 提要实现一种代理):

string url = string.Format("{0}?List={1}", SPUrlUtility.CombineUrl(web.Url, "_layouts/15/listfeed.aspx"), list.ID);
var request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
    using (var stream = response.GetResponseStream())
    {
        using (var reader = new StreamReader(stream))
        {
            result = reader.ReadToEnd();
        }
    }
    result = Regex.Replace(result, @"<enclosure.+?/>", string.Empty);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM