In last article, I showed how to create Global Calendar WebPart
Continue for this solution, I would like to introduce how to deliver Meeting Request from Calendar. So that, all event in calendar will be showed in Google Calendar or Outlook calendar as well.
Functional requirements in brief:
– Scheduling: Instant meeting management, send invitation, automated notifications and attendee confirmations (using outlook notification or google calendar notification).
SharePoint Calendar
Outlook Calendar
Firstly, I will declare a class named MeetingRequest with some function for SMTP functional
class MeetingRequest
{
//Get the site ID
public static string GetSMTPHostName(Guid siteID)
{
using (SPSite site = new SPSite(siteID))
{
//Get the SMTP host name from “Outgoing e-mail settings”
return site.WebApplication.OutboundMailServiceInstance.Parent.Name;
}
}
//Get Outgoing email server settings
public static string GetFromEmailID(Guid siteID)
{
using (SPSite site = new SPSite(siteID))
{
//Get the “from email address” from “Outgoing e-mail settings”
return site.WebApplication.OutboundMailSenderAddress;
}
}
//Send Meeting Request with
public static void SendMeetingRequest(SPWeb web, string listName, int itemID, string organizerEmail, List<string> toEmailList, string title, string body)
{
Guid siteID = web.Site.ID;
iCal ical = new iCal();
string icalData = ical.GetICSFormat(web, listName, itemID, organizerEmail);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(organizerEmail);
if (toEmailList.Count > 0)
{
for (int i = 0; i < toEmailList.Count; i++)
{
msg.To.Add(toEmailList[i]);
}
}
msg.Subject = title;
msg.Body = body;
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, new ContentType(“text/html; method=request; charset=UTF-8;component=vevent”));
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(“text/calendar”);
ct.Parameters.Add(“method”, “REQUEST”);
AlternateView avCal = AlternateView.CreateAlternateViewFromString(icalData, ct);
msg.AlternateViews.Add(avCal);
msg.AlternateViews.Add(htmlView);
SmtpClient clt = new SmtpClient(GetSMTPHostName(siteID));
try
{
clt.Send(msg);
}
catch { }
}
}
As you see, I build a class named iCal, actually I will generate an ICS file format depend on type of Request is normal request, all day request or recurrence request. You can find this class in attachment in this article.
Important Note: SendMeetingRequest method will get SMTP outgoing mail server name. So your SharePoint server must be configured for outgoing mail server. To implement this, you can check:
For SharePoint 2007: http://technet.microsoft.com/en-us/library/cc263462%28office.12%29.aspx#section2
For SharePoint 2010
http://technet.microsoft.com/en-us/library/cc288949.aspx#section5
This code works perfectly for Creating a meeting and Deleting a meeting but not working for updating a meeting.
Yes, for updating a meeting. we should provide meeting ID to update the event in calendar.
By any chance you have the code for updating the message.
i am sorry, I am really a newbie in the MS Visual Studio Programming, especially for SharePoint integration.
Basically what I need to ask are:
1. in which part of Visual Studio I can write the code and use the class (how to do it?)
2. how to put it in SharePoint?
The help will save my life in front of my bos 😀 Thank you very much.
You can download SDK for SharePoint 2007: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=79
Install and use it with VS 2008.
After that VS 2008 allow you to create an empty SharePoint project, so that you can create a webpart or a aspx page and use the class.
If you are administrator not as a developer, I suggest you use “Connect To Outlook” feature to synchronize SharePoint calendar with your outlook calendar. You can find this feature from Action menu of Calendar view.
Hi,
Thanks for the post. But i am not able to download iCal.Cs file.
Can you please send it to my mentioned email address? Thanks….
Sent to your provided email.
Didnt work for me…It only sends a regular email….I wonder why
It should be a meeting request. Please check you code careful or test on Gmail.
Hi Nhutcmos,
I am a follower of your blog posts and your Calendar entry blog post helped me in great way in creating solution of mine.
My requirement is to enable users to create meeting request from Sharepoint calendar.
I will briefly explain what i have done:
1) Create a Sharepoint list of Calendar type.
2) Create event receivers for ItemAdding and ItemUpdating which halt the users from entering
double bookings
I am able to complete the above parts but am not able to check double bookings for recurrence events.I understood that for recurrence events “fRecurrence=1”.
But to tell you the truth i am not sure how to implement the logic for this.
Can you please spare some time and explain me about this.(I want this in event receiver only and not through the iCal.cs approach you have taken).
This will be a great blog post if you write and i am sure lot of users will be looking forward to it.
Hi Rajesh.
It’s ok for your request. I thought it’s neccessary for everybody
Sure that I will try for a post relate about this subject. It should be done before end of Aug 🙂
Thanks,
Waiting for the solution 🙂
Eh, I just remember another my post related to your solution.
It should be helpful and meet to your requirement
Just update for related post as above
Cheers
Hi, great article, great code. I had a lot of problems with time zones and daylight saving time with it. So I decided to take a trial on another solution that worked for me.
http://www.sapiens.at/en/products/pages/sharepoint-calendar-e-mail-extension-3.0.aspx
Can you please email iCal.cs file to me.
Thanks,
Kamran
Can you download from https://docs.google.com/file/d/0B55FfAMp1BXdNjIyYTY0NWMtMGY1Ny00NzEyLWI5YjItOGMwMjEzZDFhZWZi/edit?pli=1
what is that itemid refers to.Is it each individual event in sharepoint calendar.Please clarify.
Hello.
First of all thank you very much for this code. This is very useful. I’m creating a set of event handlers to send the invitation (iCal) to Outlook.
I think I found a bug and would like to validate. From already thank you very much!
The situation is to change a particular date for a recurring event. By submitting the appointment to Outlook, this generates an error. Analyzing quite why the error occurs, it is the lack of UID in iCal.
When performing a debug, I see the “MasterSeriesItemID” field is null which strikes me.
It is where I compare iCal.cs with CodePlex (“http://cks.codeplex.com/releases/view/4234”).
I see your code has commented these lines:
// Loop through each item and write it to the file
// Foreach (item in list.Items SPListItem)
// {
// WriteEvent (item, timeZone, idToGuid);
} //
This is logical,
– Codeplex: Export the entire calendar
– Your version: only one item.
However the problem is not loaded “idToGuid ‘table. Then you can not find MasterSeriesItemID values.
The problem is fixed just try adding these lines:
foreach (SPListItem item1 in list.Items)
{
String guid = ((String) item1 [“GUID”]) Trim (new char [] {‘{‘, ‘}’}).;
idToGuid.Add (item1.ID, guid);
}
What is your opinion? Of course I appreciate and thank you for the code and resolution.
Greetings,
Do I need to create the Global Calendar WebPart with Recurrence Event query first before I create this one?
Sorry forgot to create a notification for my question
HI,
I used your code but during the day light saving(UTC+1), in the email event it add plus one hour to the start time and end time.
Thank Sukesh and well noted.