locked
Reading and writing User-defined fields in Calendar using EWS RRS feed

  • Question

  • I'm able to write to an extended property using EWS.  But I have no idea what ExtendedFieldURI.PropertyID to use.  The one I have is 34101, which is Billing Information.  I don't want to use that field, I want to create my own User-defined field.

    When I run the code below it puts "123" inside of the Billing Information field.
    Code Snippet

    Dim esb As New ExchangeServiceBinding
    esb.Url = "http://server/ews/exchange.asmx"
    esb.Credentials = New System.Net.NetworkCredential("user", "password", "domain")

    Dim request As New CreateItemType

    request.Items = New NonEmptyArrayOfAllItemsType
    request.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendOnlyToAll
    request.SendMeetingInvitationsSpecified = True

    Dim calendar As New CalendarItemType

    With calendar
    .ExtendedProperty = New ExtendedPropertyType(0) {}
    .ExtendedProperty(0) = New ExtendedPropertyType
    .ExtendedProperty(0).ExtendedFieldURI = New PathToExtendedFieldType
    .ExtendedProperty(0).ExtendedFieldURI.DistinguishedPropertySetId = DistinguishedPropertySetType.Common
    .ExtendedProperty(0).ExtendedFieldURI.DistinguishedPropertySetIdSpecified = True
    .ExtendedProperty(0).ExtendedFieldURI.PropertyId = 34101
    .ExtendedProperty(0).ExtendedFieldURI.PropertyIdSpecified = True
    .ExtendedProperty(0).ExtendedFieldURI.PropertyType = MapiPropertyTypeType.String
    .ExtendedProperty(0).Item = "123"

    .Body = New BodyType
    .Body.BodyType1 = BodyTypeType.HTML
    .Body.Value = "This is the <b>body</b>"

    .End = Now.AddHours(2)
    .EndSpecified = True

    .Location = "This is the location"

    .ReminderMinutesBeforeStart = "30"
    .ReminderIsSet = True
    .ReminderIsSetSpecified = True

    .Start = Now.AddHours(1)
    .StartSpecified = True

    .Subject = "This is the subject"

    End With

    request.Items.Items = New ItemType(0) {}
    request.Items.Items(0) = calendar

    Try
    Dim createItemResponse As CreateItemResponseType = esb.CreateItem(request)
    Dim responseMessages As ArrayOfResponseMessagesType = createItemResponse.ResponseMessages
    Dim responseMessage As ResponseMessageType = responseMessages.Items(0)

    If responseMessages.Items(0).ResponseClass = ResponseClassType.Error Then
    Throw New Exception(responseMessages.Items(0).MessageText)
    End If

    Catch ex As Exception
    Response.Write(ex.Message)
    End Try


    I'm still working on reading values in too.
    Wednesday, September 3, 2008 12:55 PM

Answers

  • If you want to define your own custom extended properties, you should define your own PropertySetId GUID to act as a "namespace" for your properties.  Then you can decide what name or dispatch id to give to your property within your namespace.  In other words, don't use one of the DistinguishedPropertySetIds as those "namespaces" belong to someone else.

     

    Of course, you will be reusing your GUID over and over again, so you want to hold it as a const or readonly static or something in your app and then set ExtendedProperty(0).ExtendedFieldURI.PropertySetId = YourGuid.ToString("D").

     

    Regarding PropertyName versus PropertyId - it is your choice.  However, you can only choose one.  In other words a given custom extended property will be identified by *either* a name or an id but not both.

    Wednesday, September 3, 2008 2:08 PM

All replies

  • If you want to define your own custom extended properties, you should define your own PropertySetId GUID to act as a "namespace" for your properties.  Then you can decide what name or dispatch id to give to your property within your namespace.  In other words, don't use one of the DistinguishedPropertySetIds as those "namespaces" belong to someone else.

     

    Of course, you will be reusing your GUID over and over again, so you want to hold it as a const or readonly static or something in your app and then set ExtendedProperty(0).ExtendedFieldURI.PropertySetId = YourGuid.ToString("D").

     

    Regarding PropertyName versus PropertyId - it is your choice.  However, you can only choose one.  In other words a given custom extended property will be identified by *either* a name or an id but not both.

    Wednesday, September 3, 2008 2:08 PM
  • Awesome, thanks!  I'm able to write my CustomExtendedProperty and I created a FindItem query using a restriction on that same property. This works PERFECTLY!


    Wednesday, September 3, 2008 3:07 PM
  • I am also trying to retrieve an extended property but am having issues building my PathToExtendedFieldType object.  Through Outlook, I created a user defined field.  Firstly, is this visible as an extended property?  If so, then how do I determine what PropertyId/PropertyName to specify?  Through Outlook Spy, I can see this property and all the information I need, but no matter what combination I try, the query does not return the user defined field in the ExtendedProperty property of the ItemType object.

    Thanks for any help at all.

    Shawn
    Thursday, September 11, 2008 11:21 PM
  • After a bit more work, it seems like it might not be possible to get the collection of user defined fields, i.e. a field that I created through Outlook via View - Arrange By - Current View - Customize Current View and then clicking on the "Fields..." button.  In Outlook Spy, I can see this field by calling the "Find" function of the UserProperties property of the contact.  I tried accessing the UserProperties property by passing in the following PathToExtendedFieldType:

    PathToExtendedFieldType xfContactType = new PathToExtendedFieldType();
    xfContactType.DistinguishedPropertySetId = DistinguishedPropertySetType.Address;
    xfContactType.PropertyId = 0xF816;
    xfContactType.PropertyType = MapiPropertyTypeType.Object;
    xfContactType.PropertyIdSpecified = true;
    xfContactType.DistinguishedPropertySetIdSpecified = true;

    The error that I get is "The MAPI property type is not supported".  This leads to me to believe that EWS simply doesn't go to that level of serialization yet.  Does anyone know if there is another way to access this kind of field?

    Thanks,

    Shawn
     


    Friday, September 12, 2008 6:17 PM