using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Meetings;
namespace Console
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://SERVERNAME:26413/sites/Vijai"))
{
using (SPWeb web = site.OpenWeb())
{
//// Get the Calendar list
SPList list = web.Lists.TryGetList("Calendar");
//// Check if the Calendar list exists
if (list != null)
{
//// Add an event to the Calendar list
SPListItem item = list.Items.Add();
item["Title"] = "New Event";
item["Description"] = "New Event created using SharePoint Object Model";
item["Location"] = "First Floor";
item["Start Time"] = DateTime.Now;
item["End Time"] = DateTime.Now.AddDays(2);
item["Category"] = "Business";
item["fAllDayEvent"] = false;
//// Update the item
item.Update();
System.Console.WriteLine(item["Title"] + " event is added successfully to the Calendar");
//// Get the existing meeting workspace
SPWeb mwsWeb=site.OpenWeb("Basic Meeting Workspace");
//// Get the Calendar list Id
string listId = list.ID.ToString();
//// Get the event Id to which the meeting workspace has to be linked
int itemId = item.ID;
//// Gets an SPMeeting object that has meeting information for the specified Web site
SPMeeting meetingInfo = SPMeeting.GetMeetingInformation(mwsWeb);
//// Link the meeting workspace website with the newly created event
string meetingURL=meetingInfo.LinkWithEvent(web, listId, itemId, "WorkspaceLink", "Workspace");
//// Dispose the SPWeb object
mwsWeb.Dispose();
System.Console.WriteLine(item["Title"]+" event is linked to the workspace "+ meetingURL.ToString());
System.Console.ReadLine();
}
else
{
System.Console.WriteLine("List does not exists in the site");
System.Console.ReadLine();
}
}
}
}
}
}