locked
Creating a CalendarItemType with attachments results in failure. Give Response MessageText: Set action is invalid for property. RRS feed

  • Question

  • Hi,

    I tried to create a simple Calendar Item with attachment on Exchange server2007_sp1 using webServices.

    But the ResponseMessageType give me the Following :

    Response MessageText: Set action is invalid for property.
    Response Class: Error
    Response Code: ErrorInvalidPropertySet

    The Sample Code for the Same as :

    static void Main(string[] args)

    {
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.Url = ServerURL;
    esb.Credentials = new NetworkCredential(user, password, domain);
    ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;


    RequestServerVersion requestVersion = null;
    requestVersion = new RequestServerVersion();
    requestVersion.Version = ExchangeVersionType.Exchange2007_SP1;

    ServerVersionInfo exchangeServerVersion = new ServerVersionInfo();

    // 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 = "My First Appointment";
    appointment.Categories = new string[] { "Category1", "Category2" };
    appointment.Importance = ImportanceChoicesType.High;
    appointment.ImportanceSpecified = true;
    appointment.ItemClass = "IPM.Appointment";
    appointment.Subject = "Discuss Exchange Development";

    // Add calendar properties to the appointment.
    appointment.Start = System.DateTime.Parse("2011-11-01T15:00:00Z");
    appointment.StartSpecified = true;
    appointment.End = System.DateTime.Parse("2011-11-01T16:00:00Z");
    appointment.EndSpecified = true;

    // Adding Attachements
    FileAttachmentType f = new FileAttachmentType();
    f.Name = "aaa";
    f.ContentId = "";
    f.ContentType = "text/HTML";
    f.ContentLocation = "abc.xml";

    FileStream fsSource = new FileStream("abc.xml", FileMode.Open, FileAccess.Read);
    byte[] bytes = new byte[fsSource.Length];
    int numBytesToRead = (int)fsSource.Length;
    int numBytesRead = 0;

    while (numBytesToRead > 0)
    {
     // Read may return anything from 0 to numBytesToRead.
     int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);
     // Break when the end of the file is reached.
     if (n == 0)
     break;
     numBytesRead += n;
     numBytesToRead -= n;
    }

    f.Content = bytes;

    FileAttachmentType[] attType = { f };

    // Following two lines are creating Error : If i comment them the it crates the entry but wihtout attachement.
    appointment.HasAttachments = true;
    appointment.Attachments = attType;

    // 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.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)
    {
    Console.WriteLine("Response MessageText: " + rmt.MessageText);
    Console.WriteLine("Response Class: " + rmt.ResponseClass);
    Console.WriteLine("Response Code: " + rmt.ResponseCode);
    }
    }

    catch (Exception e)

    {

    Console.WriteLine("Error Message: " + e.Message);

    }

    }

    Please Suggest :

    Thanks,

    Yogi.

     



    Tuesday, November 1, 2011 9:27 AM

All replies

  • It's been suggested that you need to create new appointment first and then create the attachments based on newly created ItemId.

    Take a look at the ItemAttachmentType and FileAttachmentType.

    Use either depending on what kind of attachment you plan to attach.

    Wednesday, November 2, 2011 2:51 PM