1

私の仕事は簡単です。2 つの日付の間のすべての会議をプルする必要があるパブリック フォルダー (実際にはカレンダー) があります。

Visual Studio 2010、ASP.Net 4.0、Microsoft Exchange Server Web Services (EWS)、および Exchange Server 2007 を使用しています。

次のコードを使用して、個人の予定表にアイテムを作成することに成功しました。

public static string[] CreateAppointment() 
{
    // Set up the binding with credentials and URL.
    com.webmail.ExchangeServiceBinding binding = new com.webmail.ExchangeServiceBinding();
    binding.Credentials = new System.Net.NetworkCredential("steve.kershaw", "mypasswordhere", "domain.com");
    binding.Url = @"https://webmail.com/ews/exchange.asmx";

    // Creating new appointment item type 
    com.webmail.CalendarItemType appointment = new com.webmail.CalendarItemType();  

    // Add properties to the newly created appointment. 
    appointment.Importance = com.webmail.ImportanceChoicesType.Normal; 
    appointment.ImportanceSpecified = true; 
    appointment.ItemClass = "IPM.Appointment"; 
    appointment.Subject = "mySubject"; 
    appointment.Body = new com.webmail.BodyType(); 
    appointment.Body.BodyType1 = com.webmail.BodyTypeType.HTML; 
    appointment.Body.Value = "<b>Body</b>";
    appointment.Categories = new string[] { "Category Red", "Category Blue" }; 
    appointment.Start = new DateTime(2013,4,30,12, 30,0); 
    appointment.StartSpecified = true; 
    appointment.End = new DateTime(2013, 4, 30, 13, 0, 0); 
    appointment.EndSpecified = true; 
    appointment.IsAllDayEvent = false; 
    appointment.IsAllDayEventSpecified = true; 
    appointment.Location = "myOffice"; 
    appointment.LegacyFreeBusyStatus = com.webmail.LegacyFreeBusyType.Busy; 
    appointment.LegacyFreeBusyStatusSpecified = true; 
    appointment.ReminderIsSet = true; 
    appointment.ReminderIsSetSpecified = true; 
    appointment.ReminderMinutesBeforeStart = "60";  

    // Specify the destination folder 
    com.webmail.DistinguishedFolderIdType folder = new com.webmail.DistinguishedFolderIdType(); 
    folder.Id = com.webmail.DistinguishedFolderIdNameType.calendar;  

    // Create the NonEmptyArrayOfAllItemsType array that will contain the appointment. 
    com.webmail.NonEmptyArrayOfAllItemsType arrayOfItems = new com.webmail.NonEmptyArrayOfAllItemsType(); 
    arrayOfItems.Items = new com.webmail.ItemType[1];  

    // Add our appointment to the array. 
    arrayOfItems.Items[0] = appointment; 

    // Create the request. 
    com.webmail.CreateItemType createItemRequest = new com.webmail.CreateItemType();  

    // Set the required SendMeetingInvitations attribute 
    createItemRequest.SendMeetingInvitations = com.webmail.CalendarItemCreateOrDeleteOperationType.SendToNone; 
    createItemRequest.SendMeetingInvitationsSpecified = true;

    // Add the destination folder to the request. 
    createItemRequest.SavedItemFolderId = new com.webmail.TargetFolderIdType(); 
    createItemRequest.SavedItemFolderId.Item = folder;  

    // Add the items to the CreateItem request. 
    createItemRequest.Items = arrayOfItems;  

    // Return value containg changeKey and hash Id to identify our appointment(needed for deleteing etc.) 
    string[] changeKeyHashId = new string[2];  
    try 
    {


        // Send the request - esb is a ExchangeServiceBinding object instance created in the Part 1 of this tutorial 
        com.webmail.CreateItemResponseType createItemResponse = binding.CreateItem(createItemRequest);  
        if (createItemResponse.ResponseMessages.Items == null || createItemResponse.ResponseMessages.Items.Length == 0) 
        { 
            return new string[] { "ERROR" }; 
        } 
        else 
        { 
            // Get the response message. 
            com.webmail.ResponseMessageType[] rmt = createItemResponse.ResponseMessages.Items;  
            if (rmt[0].ResponseClass != com.webmail.ResponseClassType.Success) 
                return new string[] 
                { "ERROR: " + rmt[0].MessageText 
                }; 
            else 
            { 
                foreach (com.webmail.ResponseMessageType rmtItem in rmt) 
                { 
                    com.webmail.ArrayOfRealItemsType itemArray = (rmtItem as com.webmail.ItemInfoResponseMessageType).Items; 
                    com.webmail.ItemType[] items = itemArray.Items;  
                    // Get the return values 
                    changeKeyHashId[0] = items[0].ItemId.ChangeKey; 
                    changeKeyHashId[1] = items[0].ItemId.Id;
                } 
            } 
        } 
    } 
    catch (Exception ex) 
    { 
        return new string[] 
        { "ERROR: " + ex.Message }; 
    }  return changeKeyHashId; 
}

ただし、自分のカレンダーを含め、任意のカレンダーから任意の予定を正常に取得するためのコードを見つけることができませんでした。私のコードの(現在の)反復は、com.webmail.GetItemResponseType resp = binding.GetItem(getItemType); で「ID の形式が正しくありません」というエラーを返します。ResponseMessages.Items.MessageText 値で返されます。これにより、返されたアイテムの値が null になります。私のコードは次のとおりです。

public static void GetCalendarItem()
{
    // Set up the binding with credentials and URL.
    com.webmail.ExchangeServiceBinding binding = new com.webmail.ExchangeServiceBinding();
    binding.Credentials = new System.Net.NetworkCredential("steve.kershaw", "mypasswordhere", "domain.com");
    binding.Url = @"https://webmail.com/ews/exchange.asmx";

    // Get the Itemtype...
    com.webmail.GetItemType getItemType = new com.webmail.GetItemType();

    ////getItemType.
    //com.webmail.GetItemResponseType getItemResponseType = binding.GetItem(getItemType);
    // Create the response shape.
    com.webmail.ItemResponseShapeType responseShape = new com.webmail.ItemResponseShapeType();
    responseShape.BodyType = com.webmail.BodyTypeResponseType.Text;
    responseShape.BodyTypeSpecified = true;
    responseShape.BaseShape = com.webmail.DefaultShapeNamesType.Default;
    // Add more properties to the request.
    com.webmail.PathToUnindexedFieldType[] sensitivity = new com.webmail.PathToUnindexedFieldType[1];
    sensitivity[0] = new com.webmail.PathToUnindexedFieldType();
    sensitivity[0].FieldURI = com.webmail.UnindexedFieldURIType.itemSensitivity;
    responseShape.AdditionalProperties = sensitivity;
    // Add the response shape to the request.
    getItemType.ItemShape = responseShape;

    // Identify the items to get.
    com.webmail.ItemIdType[] items = new com.webmail.ItemIdType[2];
    items[0] = new com.webmail.ItemIdType();
    items[0].Id = "AAAlAE1BQG1";
    items[0].ChangeKey = "DwAAABYAAAA";
    items[1] = new com.webmail.ItemIdType();
    items[1].Id = "AAAlAE1BQG1";
    items[1].ChangeKey = "DwAAABYAAAA";

    // Add items to the request.
    getItemType.ItemIds = items;

    try
    {
        // Send the request and get the response.
        com.webmail.GetItemResponseType resp = binding.GetItem(getItemType);
        com.webmail.ArrayOfResponseMessagesType aormt = resp.ResponseMessages;
        com.webmail.ResponseMessageType[] rmta = aormt.Items;

        foreach (com.webmail.ResponseMessageType rmt in rmta)
        {
            com.webmail.ItemInfoResponseMessageType iirmt = (rmt as com.webmail.ItemInfoResponseMessageType);
            com.webmail.ArrayOfRealItemsType aorit = iirmt.Items;
            com.webmail.ItemType[] myItems = aorit.Items;

            // Determine the type for each item and cast to the approriate type.
            foreach (com.webmail.ItemType it in myItems)
            {
                // Check whether it is an e-mail.
                if (it is com.webmail.MessageType)
                {
                    com.webmail.MessageType message = (it as com.webmail.MessageType);
                }
                // Determine whether it is a calendar item.
                else if (it is com.webmail.CalendarItemType)
                {
                    com.webmail.CalendarItemType calendar = (it as com.webmail.CalendarItemType);
                }
                else
                {
                    // Check for other item types.
                }
            }
        }
    }
    catch (Exception e)
    {
        throw new Exception("GetItem failed");
    }
}

特定の日付範囲のカレンダー内のすべての予定を取得する簡単な方法はありますか?!

4

1 に答える 1