分享点2010项目添加插入日历上的重复数据

时间:2012-02-20 14:44:18

标签: sharepoint sharepoint-2010

我正在尝试使用ItemAdding事件在日历上添加一些重复数据。我的代码如下:

 public override void ItemAdding(SPItemEventProperties properties)
        {
            string evtTitle = Console.ReadLine();

            SPListCollection listCollectioon = properties.List.ParentWeb.Lists;
            SPList list = listCollectioon.TryGetList("Calendar");
            SPListItemCollection listItems = list.Items;

            SPListItem recEvent = listItems.Add();

            string recData = "<recurrence><rule>" +
                "<firstDayOfWeek>su</firstDayOfWeek>" +
                "<repeat><daily dayFrequency='1' /></repeat>" +
                "<repeatInstances>1</repeatInstances></rule></recurrence>";

            recEvent["Title"] = evtTitle;
            recEvent["RecurrenceData"] = recData;
            recEvent["EventType"] = 1;
            recEvent["EventDate"] = new DateTime(2012, 3, 1, 8, 0, 0);
            recEvent["EndDate"] = new DateTime(2012, 3, 12, 9, 0, 0);
            recEvent["UID"] = System.Guid.NewGuid();
            recEvent["TimeZone"] = 13;
            recEvent["Recurrence"] = -1;
            recEvent["XMLTZone"] = "<timeZoneRule>" +
                "<standardBias>480</standardBias>" +
                "<additionalDaylightBias>-60</additionalDaylightBias>" +
                "<standardDate><transitionRule  month='10' day='su' weekdayOfMonth='last' />" +
                "<transitionTime>2:0:0</transitionTime></standardDate>" +
                "<daylightDate><transitionRule  month='4' day='su' weekdayOfMonth='first' />" +
                "<transitionTime>2:0:0</transitionTime>" +
                "</daylightDate></timeZoneRule>";

            recEvent.Update();
            listItems.Add();



            base.ItemAdding(properties);


        }

但问题是它在同一个日期创建了10个单独的事件。我无法理解这个以及我如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

这适合我。

SPList calendar = web.Lists["Calendar"];
                SPListItem recEvent = calendar.Items.Add();

                //string recData = "<recurrence><rule>" +
                //    "<firstDayOfWeek>su</firstDayOfWeek>" +
                //    "<repeat><daily dayFrequency=\"1\" /></repeat>" +
                //    "<repeatInstances>1</repeatInstances></rule></recurrence>";

                string recData = "<recurrence><rule><firstDayOfWeek>su</firstDayOfWeek><repeat><daily dayFrequency=\"1\" /></repeat><windowEnd>2012-02-26T01:00:00Z</windowEnd></rule></recurrence>";


                recEvent["Title"] = "Test 1";
                recEvent["RecurrenceData"] = recData;
                recEvent["EventType"] = 1;
                recEvent["Start Time"] = new DateTime(2012, 2, 21, 10, 0, 0);
                recEvent["End Time"] = new DateTime(2012, 2, 25, 11, 0, 0);
                recEvent["TimeZone"] = 10;
                recEvent["Recurrence"] = true;
                recEvent["XMLTZone"] = "<timeZoneRule><standardBias>300</standardBias><additionalDaylightBias>-60</additionalDaylightBias><standardDate><transitionRule  month='11' day='su' weekdayOfMonth='first' /><transitionTime>2:0:0</transitionTime></standardDate><daylightDate><transitionRule  month='3' day='su' weekdayOfMonth='second' /><transitionTime>2:0:0</transitionTime></daylightDate></timeZoneRule>";
                recEvent.Update();
                calendar.Update();

“repeatInstance”如果要将重复事件限制为特定数字或使用“windowEnd”