none
Exchange 2010 EWS - CreateItem in a subfolder RRS feed

  • Question

  • I'm trying to figure out how to write a new contact to a subfolder named Directory Contacts under the Contacts folder. The code below successfully creates the test contact into the Contacts folder, but I want to target the subfolder instead. Not having much luck in finding a way to do that.

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> 
      <soap:Header> 
    <t:RequestServerVersion Version="Exchange2010"/> 
      <t:ExchangeImpersonation> 
       <t:ConnectingSID> 
        <t:PrimarySmtpAddress>rusty.burns@alston.com</t:PrimarySmtpAddress> 
       </t:ConnectingSID> 
      </t:ExchangeImpersonation> 
     </soap:Header> 
     <soap:Body> 
      <CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" > 
       <SavedItemFolderId> 
        <t:DistinguishedFolderId Id="contacts"/> 
       </SavedItemFolderId> 
       <Items> 
        <t:Contact> 
         <t:FileAs>SampleContact</t:FileAs> 
         <t:GivenName>Tanja</t:GivenName> 
         <t:CompanyName>Blue Yonder Airlines</t:CompanyName> 
         <t:EmailAddresses> 
          <t:Entry Key="EmailAddress1">tplate@example.com</t:Entry> 
         </t:EmailAddresses> 
         <t:PhysicalAddresses> 
          <t:Entry Key="Business"> 
           <t:Street>1234 56th Ave</t:Street> 
           <t:City>La Habra</t:City> 
           <t:State>CA</t:State> 
          </t:Entry> 
         </t:PhysicalAddresses> 
         <t:PhoneNumbers> 
          <t:Entry Key="BusinessPhone">4255550199</t:Entry> 
         </t:PhoneNumbers> 
         <t:JobTitle>Manager</t:JobTitle> 
         <t:Surname>Plate</t:Surname> 
        </t:Contact> 
       </Items> 
      </CreateItem> 
     </soap:Body> 
    </soap:Envelope>
    
    Wednesday, June 8, 2011 1:55 PM

Answers

  • Hello r_burns,

    You are already there. Since you chose a shallow search of the Contacts folder, you have all the folders directly under the default Contacts folder. If you are concerned about a deeper inspection, make it a Deep traversal search.

    Since you chose the default shape, you already get the display name of each folder in your result set. You can search your local result set for the target folder OR you can have the Exchange Server limit the result set by adding a Restriction element before the ParentFolderIds element. The choice between client-side versus server-side filtering should be made with consideration around performance for the server.

    Here is the Restriction element for performing the filtering on the server:

    <Restriction>
       <t:Contains ContainmentMode="ExactPhrase" ContainmentComparison="Exact">
          <t:FieldURI FieldURI="folder:DisplayName" />
          <t:Constant Value="Directory Contacts" />
       </t:Contains>
    </Restriction>

    With regards,


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, June 13, 2011 5:26 PM
    Moderator

All replies

  • Hello r-burns,

    You need to first create a folder in the Contacts folder. Use the CreateFolder operation (see example http://msdn.microsoft.com/en-us/library/aa563574(EXCHG.140).aspx). The response will contain the identifier of the new folder which you will use in the subsequent CreateItem operation. If you already have created the Directory Contacts folder, then you need to find the identifier of that folder (use the FindFolder operation, http://msdn.microsoft.com/en-us/library/aa563918(EXCHG.140).aspx). Then use the CreateItem operation with FolderId (instead of DistinguishedFolderId) element to identify the target folder.

    La Habra, CA, eh, my old stomping grounds.

    With regards,


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, June 8, 2011 9:47 PM
    Moderator
  • Thanks Michael. The code below runs fine and returns an ID, but how do I know this is the Directory Contacts folder? A user may have multiple subfolders. Is there a way to tell it to specifically look for "Directory Contacts" under the Contacts folder?

     

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <soap:Header>
    <t:RequestServerVersion Version="Exchange2010"/>
        <t:ExchangeImpersonation>
          <t:ConnectingSID>
            <t:PrimarySmtpAddress>myemail@mydomain.com</t:PrimarySmtpAddress>
          </t:ConnectingSID>
        </t:ExchangeImpersonation>
      </soap:Header>
      <soap:Body>
        <FindFolder Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
          <FolderShape>
            <t:BaseShape>Default</t:BaseShape>
          </FolderShape>
          <ParentFolderIds>
            <t:DistinguishedFolderId Id="contacts"/>
          </ParentFolderIds>
        </FindFolder>
      </soap:Body>
    </soap:Envelope>

     

    Friday, June 10, 2011 6:33 PM
  • Hello r_burns,

    You are already there. Since you chose a shallow search of the Contacts folder, you have all the folders directly under the default Contacts folder. If you are concerned about a deeper inspection, make it a Deep traversal search.

    Since you chose the default shape, you already get the display name of each folder in your result set. You can search your local result set for the target folder OR you can have the Exchange Server limit the result set by adding a Restriction element before the ParentFolderIds element. The choice between client-side versus server-side filtering should be made with consideration around performance for the server.

    Here is the Restriction element for performing the filtering on the server:

    <Restriction>
       <t:Contains ContainmentMode="ExactPhrase" ContainmentComparison="Exact">
          <t:FieldURI FieldURI="folder:DisplayName" />
          <t:Constant Value="Directory Contacts" />
       </t:Contains>
    </Restriction>

    With regards,


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, June 13, 2011 5:26 PM
    Moderator
  • Thanks Michael. Worked like a charm except the folder I created was a regular folder rather than a Contacts folder type. Could you please let me know what I would add to the XML below to let EWS know to make this folder a Contacts type folder?

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <soap:Header>
    <t:RequestServerVersion Version="Exchange2010"/>
        <t:ExchangeImpersonation>
          <t:ConnectingSID>
            <t:PrimarySmtpAddress>myemail@mydomain.com</t:PrimarySmtpAddress>
          </t:ConnectingSID>
        </t:ExchangeImpersonation>
      </soap:Header>
      <soap:Body>

    <CreateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <ParentFolderId xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
        <DistinguishedFolderId Id="contacts" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
      </ParentFolderId>
      <Folders xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
        <Folder xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
          <DisplayName>Directory Contacts</DisplayName>
        </Folder>
      </Folders>
    </CreateFolder>
    </soap:Body>
    </soap:Envelope>

     

    Friday, June 17, 2011 5:11 PM
  • Hello r_burns,

    Change the following:

    <Folders xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <Folder xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
       <DisplayName>Directory Contacts</DisplayName>
      </Folder>
    </Folders>

    to:

    <Folders xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <ContactsFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
        <DisplayName>Directory Contacts</DisplayName>
      </ContactsFolder>
    </Folders>

    With regards,


    Michael | Microsoft Exchange SDK

    The Exchange Development Forum Guide has useful information for using the Exchange Development Forum.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, June 20, 2011 6:20 PM
    Moderator