locked
Set/Retrieve UserProperties on calendar folder? RRS feed

  • Question

  • Hi,

    Is there a possible way to set/retrieve UserProperties on calendar folder in an Outlook Addin?

    Thanks,

    KREMERS Bertrand

    Monday, March 31, 2014 6:53 AM

Answers

  • Hello Bertrand,

    You can add user properties for folders if you deal with pst files. But if you want to support Exchange server profiles you need to use another solution. The most elegant way would be to add a StorageItem object.

    The Outlook object model does not provide any collection object for StorageItem objects. However, you can use Folder.GetTable to obtain a Table with all the hidden items in a Folder, when you specify  the TableContents parameter as olHiddenItems. If keeping your data private is of a high concern, you should encrypt the data before storing it. Here is what MSDN states for storage items:

    You can do the following to store solution data:           

    • Add attachments to the item for storage.

    • Use explicit built-in properties of the item such as Body to store custom data.

    • Add custom properties to the item using UserProperties.Add method. Note that in this case, the optional AddToFolderFields and DisplayFormat arguments of the UserProperties.Add method will be ignored.

    • Use the PropertyAccessor object to get or set custom properties.

    Read more about this in the Storing Data for Solutions article in MSDN.

    Sub AssignStorageData()  
     Dim oInbox As Outlook.Folder  
     Dim myStorage As Outlook.StorageItem 
     
     Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)  
     ' Get an existing instance of StorageItem, or create new if it doesn't exist  
     Set myStorage = oInbox.GetStorage("My Private Storage", olIdentifyBySubject)
     ' If StorageItem is new, add a custom property for Order Number  
     If myStorage.Size = 0 Then  
        myStorage.UserProperties.Add "Order Number", olNumber  
     End If  
     ' Assign a value to the custom property  
     myStorage.UserProperties("Order Number").Value = 100  
     myStorage.Save  
    End Sub 



    • Edited by Eugene Astafiev Monday, March 31, 2014 8:45 AM
    • Proposed as answer by George Hua Tuesday, April 1, 2014 6:50 AM
    • Marked as answer by George Hua Monday, April 7, 2014 4:39 PM
    Monday, March 31, 2014 8:43 AM

All replies

  • On the MAPIFolder object? No, named MAPI properties in general are supported by the items only, not by folders.

    PST provider supports named properties on folders, Exchange provider does not.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, March 31, 2014 7:06 AM
  • Hi,

    Thanks for your answer. So if I understand, there is no way to set UserProperties on folders. Then, what are possible solutions for me? StorageItem? Think it's the only way.

    Thanks,

    Monday, March 31, 2014 7:29 AM
  • Hello Bertrand,

    You can add user properties for folders if you deal with pst files. But if you want to support Exchange server profiles you need to use another solution. The most elegant way would be to add a StorageItem object.

    The Outlook object model does not provide any collection object for StorageItem objects. However, you can use Folder.GetTable to obtain a Table with all the hidden items in a Folder, when you specify  the TableContents parameter as olHiddenItems. If keeping your data private is of a high concern, you should encrypt the data before storing it. Here is what MSDN states for storage items:

    You can do the following to store solution data:           

    • Add attachments to the item for storage.

    • Use explicit built-in properties of the item such as Body to store custom data.

    • Add custom properties to the item using UserProperties.Add method. Note that in this case, the optional AddToFolderFields and DisplayFormat arguments of the UserProperties.Add method will be ignored.

    • Use the PropertyAccessor object to get or set custom properties.

    Read more about this in the Storing Data for Solutions article in MSDN.

    Sub AssignStorageData()  
     Dim oInbox As Outlook.Folder  
     Dim myStorage As Outlook.StorageItem 
     
     Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)  
     ' Get an existing instance of StorageItem, or create new if it doesn't exist  
     Set myStorage = oInbox.GetStorage("My Private Storage", olIdentifyBySubject)
     ' If StorageItem is new, add a custom property for Order Number  
     If myStorage.Size = 0 Then  
        myStorage.UserProperties.Add "Order Number", olNumber  
     End If  
     ' Assign a value to the custom property  
     myStorage.UserProperties("Order Number").Value = 100  
     myStorage.Save  
    End Sub 



    • Edited by Eugene Astafiev Monday, March 31, 2014 8:45 AM
    • Proposed as answer by George Hua Tuesday, April 1, 2014 6:50 AM
    • Marked as answer by George Hua Monday, April 7, 2014 4:39 PM
    Monday, March 31, 2014 8:43 AM
  • Hi,

    Thank you very much for your response, which is very clear! I'v done it, and it works! But now, and it seems to be impossible, how can I retrieve that StorageItem using EWS Managed API in another application? Hope you've got the answer.

    Monday, March 31, 2014 8:53 AM
  • Hello Bertrand,

    I have already answered you. Please check out the following forum threads:

    Retrieve StorageItem created in Outlook addin with EWS Managed API?

    Retrieve StorageItem created in Outlook addin?

    Monday, March 31, 2014 9:11 AM
  • Please see my reply at http://social.msdn.microsoft.com/Forums/vstudio/en-US/5d7f29ac-2985-41c9-a8aa-587aa2d5dafb/retrieve-storageitem-created-in-outlook-addin?forum=vsto


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, March 31, 2014 2:03 PM