none
Cannot read post item's UserProperties if it is not open in an inspector RRS feed

  • Question

  • Hello,

    I'm developing a software for support a business process using Add-ins for Outlook 2010.

    Developing a report I faced a strange behaver in the Add-in. In the code below I read one by one a notes from a folder and I for an unknown reason UserProperties could not find user defined properties if a note was not open in an inspector windows. In order to bypass the issue I open and immediately close the message. It works but makes annoying windows flickering.

    May be somebody know how avoid this behaviour?  

    I believe it is possible, because if I make the quick watch of variable "note" in my Visual Studio debugger it gives me ALL UserProperties for a note and a code behind a break point can read the properties of this note too.

    Public Sub GenerateReport() Dim folder As Outlook.Folder = Globals.ThisAddIn.GetInteractionFolder() Try Dim note As Outlook.PostItem For Each note In folder.Items If note.UserProperties.Count = 0 Then note.Display() note.Close(Outlook.OlInspectorClose.olDiscard) ' now note.UserProperties.Count is 19 End If xlWs.Cells(1, 1).Value = note.UserProperties.Find("Caller").Value . . . Next note

    Catch ex As Exception End Try

    Kingest regards

    Iserik

     


    • Edited by Iserik Wednesday, May 13, 2015 5:48 AM
    Wednesday, May 13, 2015 5:42 AM

Answers

  • Do you see both the blob with the property definitions and/or their values?

    Does the problem go away if you call GetInspector instead of Display?


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

    • Marked as answer by Iserik Wednesday, May 20, 2015 12:02 AM
    Thursday, May 14, 2015 6:08 PM

All replies

  • Do you see the user properties (both the blob with the properties definitions and the actual named property that stores the value) in OutlookSpy (click IMessage)?

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

    Wednesday, May 13, 2015 5:46 AM
  • Hello Iserik,

    The folder may contain a lot of Outlook items. I'd suggest using the Find/FindNext or Restrict methods of the Items class to find items that corresponds to the defined condition instead. You can read more about these methods in the following series of articles:

    How To: Use Restrict method to retrieve Outlook mail items from a folder

    How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)

    If note.UserProperties.Count = 0 Then

    Also I'd suggest breaking the chain of calls and declaring each property or method call on a separate line of code. It will allow to release underlying COM objects instantly.

    Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. This is particularly important if your add-in attempts to enumerate more than 256 Outlook items in a collection that is stored on a Microsoft Exchange Server. If you do not release these objects in a timely manner, you can reach the limit imposed by Exchange on the maximum number of items opened at any one time. Read more about that in the Systematically Releasing Objects article in MSDN.

     Use the for loop instead of the foreach one.
    For Each note In folder.Items
       

    Wednesday, May 13, 2015 5:53 AM
  • Dear Dmitry Streblechenko 

    Yes, I can see User properties in your tool OutlookSpy

    • Edited by Iserik Wednesday, May 13, 2015 6:38 AM
    Wednesday, May 13, 2015 6:22 AM
  • Iserik,

    Have you tried to apply all what I said in previous post there? If so, may I see the updated code?

    Wednesday, May 13, 2015 11:17 AM
  • Iserik,

    Have you tried to apply all what I said in previous post there? If so, may I see the updated code?

    Eugene,

    Thank you for your suggestions.

    Yes, I did change code as you insisted. Part of the code is attached below. I removed a lot of real code but its core is here. Bottom line is it is NOT working properly. The issue remains the same.

    I tried to restricted search by a criteria using Find/FindNext or Restrict but it didn't work

           
            Dim folder As Outlook.Folder = Globals.ThisAddIn.GetInteractionFolder()
    		Dim itsNotes As Outlook.Items
    		Dim item As Object
    		
            Try
                itsNotes = folder.Items
                item = itsNotes.GetFirst()
                While item IsNot Nothing
                    Dim note As Outlook.PostItem = TryCast(item, Outlook.PostItem)
                    If note IsNot Nothing AndAlso _
                        (note.MessageClass = "IPM.Post.xx2" Or note.MessageClass = "IPM.Post.xx1") _
                    Then
    			
    	          If note.UserProperties.Count = 0 Then
                        note.Display()
                        note.Close(Outlook.OlInspectorClose.olDiscard)
    					' now note.UserProperties.Count is 19
                      End If
    				
                      xlWs.Cells(1, 1).Value = note.UserProperties.Find("Caller").Value
    				.
    				.
    				.
                    ReleaseComObject(item)
                    item = itsNotes.GetNext
                End While            
            End Try


    • Edited by Iserik Thursday, May 14, 2015 2:48 AM
    Thursday, May 14, 2015 1:30 AM
  • Do you see the user properties (both the blob with the properties definitions and the actual named property that stores the value) in OutlookSpy (click IMessage)?

    Dmitry,

    I downloaded and installed your great tool played with it around the problem.

    I found that I can see in your tool the user-defined properties using IMessage interface, however when I use "Item" from Outlook object Model of your tool it also gave me UserProperties.Count = 0

    Some ideas?

     Regards




    • Edited by Iserik Thursday, May 14, 2015 8:18 AM
    Thursday, May 14, 2015 7:53 AM
  • Do you see both the blob with the property definitions and/or their values?

    Does the problem go away if you call GetInspector instead of Display?


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

    • Marked as answer by Iserik Wednesday, May 20, 2015 12:02 AM
    Thursday, May 14, 2015 6:08 PM

  • Does the problem go away if you call GetInspector instead of Display?

    Thank you Dmitry. The issue is solved replacing Display with GetInspector. There are not any flickering now and report works smoothly.
    Wednesday, May 20, 2015 12:07 AM