以下是方法:
#region 给本人插入会议日程
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Mail;
using System.Net.Mime;
using System.Net;
using System.Text;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
public void CreateAppointment(ExchangeServiceBinding esb, string sub, string roommail, string location, DateTime datefrom, DateTime dateto,string bodyvalue)
{
// Create the appointment.
CalendarItemType appointment = new CalendarItemType();
// Add item properties to the appointment.
appointment.Body = new BodyType();
appointment.Body.BodyType1 = BodyTypeType.Text;
appointment.Body.Value = bodyvalue;//"Agenda Items.";
//appointment.Categories = new string[] { "Category1", "Category2" };
appointment.Importance = ImportanceChoicesType.High;
appointment.ImportanceSpecified = true;
appointment.ItemClass = "IPM.Appointment";
appointment.Subject = sub;
// Add an attendee
MailAddressCollection mc = GetrMailAddressList();
AttendeeType[] rAtt = new AttendeeType[mc.Count];
for (int ii = 0; ii < rAtt.Length; ii++)
{
EmailAddressType eat = new EmailAddressType();
eat.EmailAddress = mc[ii].Address;
eat.Name = mc[ii].DisplayName;
AttendeeType att = new AttendeeType();
att.Mailbox = eat;
rAtt[ii] = att;
}
//EmailAddressType eat1 = new EmailAddressType();
//eat1.EmailAddress = "第一个与会者邮箱地址";
//eat1.Name = "姓名";
//AttendeeType at1 = new AttendeeType();
//at1.Mailbox = eat1;
//EmailAddressType eat2 = new EmailAddressType();
//eat2.EmailAddress = "第一二个与会者邮箱地址";
//eat2.Name = "姓名";
//AttendeeType at2 = new AttendeeType();
//at2.Mailbox = eat2;
//AttendeeType[] rAtt = new AttendeeType[2];
//rAtt[0] = at1;
//rAtt[1] = at2;
appointment.RequiredAttendees = rAtt;
//add meeting room attendee
EmailAddressType meetingRoom = new EmailAddressType();
meetingRoom.EmailAddress = roommail ;// "会议室邮箱地址";
meetingRoom.Name = location ;
AttendeeType meetingType = new AttendeeType();
meetingType.Mailbox = meetingRoom;
AttendeeType[] meetingTypeList = new AttendeeType[1];
meetingTypeList[0] = meetingType;
appointment.Resources = meetingTypeList;
appointment.Location = location;
// Add calendar properties to the appointment.
appointment.Start = datefrom;
appointment.StartSpecified = true;
appointment.End = dateto;
appointment.EndSpecified = true;
// Identify the destination folder that will contain the appointment.
DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
folder.Id = DistinguishedFolderIdNameType.calendar;
// Create the array of items that will contain the appointment.
NonEmptyArrayOfAllItemsType arrayOfItems = new NonEmptyArrayOfAllItemsType();
arrayOfItems.Items = new ItemType[1];
// Add the appointment to the array of items.
arrayOfItems.Items[0] = appointment;
// Create the CreateItem request.
CreateItemType createItemRequest = new CreateItemType();
// The SendMeetingInvitations attribute is required for calendar items.
//createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToNone;
createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToAllAndSaveCopy;
createItemRequest.SendMeetingInvitationsSpecified = true;
// Add the destination folder to the CreateItem request.
createItemRequest.SavedItemFolderId = new TargetFolderIdType();
createItemRequest.SavedItemFolderId.Item = folder;
// Add the items to the CreateItem request.
createItemRequest.Items = arrayOfItems;
try
{
// Send the request and get the response.
CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);
// Get the response messages.
ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items;
foreach (ResponseMessageType rmt in rmta)
{