Monday, May 26, 2014

Recurring Events in SharePoint Calendar - C#

Hello all,


I am trying to populate recurring calendar events from a workflow.


I have been following these articles, which explain exactly what I am trying to achieve:


http://ift.tt/1nM5c4U


http://ift.tt/1npsz61


I have followed all the steps listed, but as soon as the workflow is triggered it reports an "Error Ocurred" message.


I have looked into the 14\log file, but I cannot get any clue from it.


Can anyone give me a hand with it? any help debugging it?


This is the defined class:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.UserCode;
using System.IO;

namespace CreateCalendarRecurrence
{
class CreateCalendarRecurrenceEvent
{
public Hashtable CalendarRecurrenceEvent(SPUserCodeWorkflowContext context, string eventTitle, string recurrenceRule)
{
Hashtable results = new Hashtable();
int iYear = 0, iMonth = 0, iDay = 0;
results["Except"] = string.Empty;
try
{
using (SPSite site = new SPSite(context.CurrentWebUrl))
{
using (SPWeb web = site.OpenWeb())
{
iYear = DateTime.Now.Year; iMonth = DateTime.Now.Month; iDay = DateTime.Now.Day;
DateTime startTime = new DateTime(iYear, iMonth, iDay, 8, 0, 0); //
DateTime endTime = startTime.AddHours(6);
SPList cal = web.Lists["CalendarTest"];
SPListItem calEvent = cal.Items.Add();
calEvent["Title"] = eventTitle;
calEvent["RecurrenceData"] = recurrenceRule;
calEvent["EventType"] = 1;
calEvent["EventDate"] = startTime;
calEvent["EndDate"] = endTime;
calEvent["UID"] = System.Guid.NewGuid();
calEvent["Recurrence"] = 1;
calEvent.Update();
}
}
}
catch (Exception ex)
{
results["Except"] = ex.ToString();
}
return results;
}
}
}

Let me know if would be beneficial to attach any other file or .log


Thanks in advance.




No comments:

Post a Comment