Erik Elkins

Creating Meetings in EWS (Exchange Web Services)

This last week I’ve been playing around with Exchange Web Services, and if you’ve ever had the pleasure, then you know resources are thin. So I may be making another one or two posts on the subject. Here’s how I’m able to create a meeting. First things first, you’ll need to initialize the ExchangeServiceBinding.

1
2
3
var Binding = new ExchangeServiceBinding(); 
Binding.Credentials = new NetworkCredential("UserName", "Password", "domain"); 
Binding.Url = @"https://server/EWS/exchange.asmx";

Server in this case would be the server name of the Exchange server you’re trying to make a connection with. Next you’ll have to make the CalendarItemType with the meeting information.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var meeting = new CalendarItemType 
{ 
   Subject = "Meeting name", 
   Body = new BodyType 
   {
      Value = "CalendarItem:TextBody", 
      BodyType1 = BodyTypeType.Text 
   }, 
   Start = DateTime.Now, 
   StartSpecified = true, 
   End = DateTime.Now.AddHours(1), 
   EndSpecified = true, 
   MeetingTimeZone = new TimeZoneType 
   { 
      TimeZoneName = TimeZone.CurrentTimeZone.StandardName, 
      BaseOffset = "PT6H" // Central 
   }, 
   Location = "Meeting Room Name", 
   RequiredAttendees = new[] 
   { 
      new AttendeeType 
      { 
         Mailbox =new EmailAddressType 
         { 
            EmailAddress = "[email protected]" 
         } 
      } 
   } 
};

As far as the MeetingTimeZone goes, you’ll have to pass in your time as represented by PTXH (PT0H for utc, PT6H, etc). Location will be a string, and will not be resolved. So if you want that room to be reserved then you’ll have to add it as an attendee, along with any other attendees you want to add. Next, you’ll have to create the CreateItemType containing the recently created CalendarItemType.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var request = new CreateItemType 
{ 
   SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToAllAndSaveCopy, 
   SendMeetingInvitationsSpecified = true, 
   SavedItemFolderId = new TargetFolderIdType 
   { 
      Item = new DistinguishedFolderIdType 
      { 
         Id = DistinguishedFolderIdNameType.calendar 
      } 
   }, 
   Items = new NonEmptyArrayOfAllItemsType 
   { 
      Items = new ItemType[] 
      { 
         meeting 
      } 
   } 
};

Now you’re ready to make the request.

1
CreateItemResponseType response = Binding.CreateItem(request);

From there you’ll be able to check if the response’s first item is of type ResponseClassType.Error, and if not, then you just successfully created a meeting.