Insert iCal Events into SharePoint 2010 Calendar

Final Result

Introduction

This article describes how to read an iCalendar file and insert the calendar events into a SharePoint 2010 calendar. It will also outline how we can show these new events as a calendar overlay to an existing SharePoint 2010 calendar so as to display it in another color and add additional view filters to these events.

Background

I am maintaining a departmental SharePoint 2010 team site which has a shared calendar object that the personnel in the departments rely on to update their out of office statuses and other departmental activities. As such, we thought it will be a good idea to also show public holidays on the calendar so staff can use it as a standard reference point to plan their work activities.

Public holidays are usually published in an iCalendar file on a government website. iCalendar, also known as RFC 2445, is a standard textual file format with the extension ".ics". It is a widely used format for exchanging and publishing calendaring and scheduling information, and it is used and supported by many calendaring products such as Google Calendar, Lotus Notes, Microsoft Outlook, etc.

Since the iCalendar files are in a standard format, there are multiple libraries available that can be used to extract the contents in the file. We will be using the Open Source DDay.iCal library to interact with the calendaring information in the iCalendar files and SharePoint 2010 Web Services to insert calendar events into the team site shared calendar.

SharePoint Calendar Setup

To keep the public holidays as a separate SharePoint calendar so that we can overlay the new calendar onto the existing departmental calendar, we would first have to create the new calendar. In your SharePoint site, create a new calendar under the List category. In this example, I have named the new calendar "Public Holidays".

Create new calendar

Referencing SharePoint 2010 Web Services

After our new calendar is set up in the SharePoint site, we will need to switch back to Visual Studio 2010 to add a reference to the Web Services that are located in the SharePoint site. Create a new "Windows Console Application" project in Visual Studio 2010. Add the references to the DDay.iCal library to your solution, namely the antlr.runtime.dll and DDay.iCal.dll files. Next, we need to add a Web Service reference to our SharePoint site. Right click on "Service Reference" in your Visual Studio solution and select "Add Service Reference".

Create Service Reference

As SharePoint 2010 is utilizing .NET 2.0 style Web Services, we will need to create Web Service references instead of service references. In the "Add Service Reference" window, click on "Advanced". A "Service Reference Settings" dialog box should pop up. Click on "Add Web Reference" to add a .NET 2.0 Web Service reference to the solution.

Adding Web Reference

At the Add Web Reference screen, type in the URL of your SharePoint site which contains the calendar, followed by the service path to the Lists.asmx Web Service. In this example, our site is named "caltest". Give a name to your Web Service reference. In this example, we have named it "WService". Click "Add Reference" to add this Web Service reference to our solution.

Setting Web Reference

Using the Code

infor details :http://www.codeproject.com/KB/sharepoint/InsertiCalEventsSP.aspx

After running the code above, the entries in the iCal file should be inserted into the "Public Holidays" calendar. When we refresh the calendar in our SharePoint site, we should see the entries being inserted and displayed on the calendar.

Imported Calendaring Entries

Adding Additional SharePoint Calendar Overlay

Now, coming to the final part of this article, we want to overlay the "Public Holiday" calendar on top of our existing department SharePoint calendar. First, go back to the main calendar and click on "Calendars in View".

Calendars in View

In the Calendar overlay screen, give a name to the overlay. In this example, we have named our overlay "Public Holiday Overlay". You will need to fill in the URL of your SharePoint site and click on the Resolve button to get SharePoint to retrieve all the calendars that are available for the particular SharePoint site. Select the calendar which you want to use as an overlay and click on the OK button.

Overlay naming

You will be returned to the Additional Calendar screen. Here you can choose which particular calendars will be visible in view. Click OK to overlay the "Public Holiday" calendar onto your existing SharePoint 2010 calendar and you're done! Congratulations!

Visible overlays

Source:www.codeproject.com

0 nhận xét:

Post a Comment

thanks comment