Hello,
We have a requirement where we need to pull all the items from sub calendars and show it in Global calendar. I created event reciever to acheive this. Item update is working fine with recurrsive pattern as well. But there is a problem with All Day Event feild, when first check it in sub calendar it is updated in global calenar, after that when i want to update the item for second time it is changing in sub calendar but it is not reflecting in Global calendar.
I think there is some problem with AllDayEvent feild, Any help would be great help. My code looks like below. Here HP Calendar exists in sub sites and RootSite. We are getting items from sub sites HP Calendar and adding it to RootSite HP Calendar.
public static SPListItem BeforePropertiesItem
{
get;
set;
}
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
BeforePropertiesItem = properties.ListItem;
}
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite oSite = properties.OpenSite();
SPWeb rootWeb = oSite.RootWeb;
//SPWeb currentWeb = oSite.OpenWeb();
SPList rootlist = rootWeb.Lists["HP calendar"];
SPList currentList = properties.List;
Guid currentListid = currentList.ID;
Guid Rootlistid = rootlist.ID;
//properties.ListItem.Fields.cout
SPListItem ChangedItem = properties.ListItem;
SPListItem OriginalItem = BeforePropertiesItem;
// Guid itemid = currentItem.UniqueId;
if (Rootlistid != currentListid)
{
SPQuery query = new SPQuery();
string startDate = (SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(OriginalItem["EventDate"])));
string endDate = (SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(OriginalItem["EndDate"])));
query.Query = string.Format("<Where><And><And><And><Eq><FieldRef Name='EventDate' /><Value Type='DateTime'>{0}</Value></Eq><Eq><FieldRef Name='EndDate' /><Value Type='DateTime'>{1}</Value></Eq></And><Eq><FieldRef
Name='Location' /><Value Type='Text'>{2}</Value></Eq></And><Eq><FieldRef Name='Title' /><Value Type='Text'>{3}</Value></Eq></And></Where>", startDate, endDate, OriginalItem["Location"],
OriginalItem["Title"]);
SPListItemCollection itemCollection = rootlist.GetItems(query);
int count = itemCollection.Count;
SPListItem Parentitem = itemCollection[0];
foreach (SPField f in ChangedItem.Fields)
{
//Copy all except attachments.
if (!f.ReadOnlyField && f.InternalName != "Attachments"
&& f.InternalName != "Facilities")
{
Parentitem[f.InternalName] = ChangedItem[f.InternalName];
}
}
Parentitem.Update();
}
});
Thanks