5

I am trying to migrate SharePoint calendar from 2007 to 2013 programatically.

Here is my code.

using (ClientContext clientcontext = new ClientContext(targetURL))
{
    clientcontext.Credentials = onlineCredentials;
    Web web = clientcontext.Web;
    Site site = clientcontext.Site;

    ListCreationInformation Listcreate = new ListCreationInformation();
    Listcreate.Title = "Calendar123";
    Listcreate.Description = "this is my test calendar";
    Listcreate.TemplateType = (int)ListTemplateType.Events;
    List oList = web.Lists.Add(Listcreate);
    clientcontext.ExecuteQuery();

    List list = clientcontext.Web.Lists.GetByTitle("Calendar123");
    ListItemCreationInformation Listitemcreate = new ListItemCreationInformation();
    ListItem item = list.AddItem(Listitemcreate);

    item["Title"] = "StandUP Call";
    item["Description"] = "StandUp call will be hold in Meeting discussion room no. 3";
    item["Location"] = "First Floor";
    item["EventDate"] = DateTime.Now; //Start Time
    item["EndDate"] = DateTime.Now.AddDays(3);
    item["Category"] = "Business";
    item["fAllDayEvent"] = true;
    item["fRecurrence"] = 1;

    item.Update();

    clientcontext.ExecuteQuery();
}

It creates an event in calendar but item["fRecurrence"] = 1 is not working properly and getting below error.

<--RENDERING FAILED-->

Because to work properly it also needs RecurrenceData and I don't know how to insert that using program.

1

You can refer this URL for RecurrenceData schema and write a C# function to generate the schema based on parameters like

  1. RecurrenceType Enum { Hourly, Daily, Monthly, Yearly}
  2. FirstDayOfWeek Enum {Su, Mon, Tue, Web, Thu, Fri, Sat}
  3. Frequency Integer
  4. WindowEnd DateTime
  5. RepeatForever Boolean
  6. RepeatInstances Integer

And set it to the RecurrenceData field of the ListItem or you can set a static XML value to it like this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.