none
DASL Filter for attachment files RRS feed

  • Question

  • Hello,

    I am using the Items.Restrict method to make a search on attachment files in a mail folder. This is my code:

    Public Const PR_ATTACH_FILENAME As String = "http://schemas.microsoft.com/mapi/proptag/0x3704001F"
    
    ....
    
    Dim folderitems As Outlook.Items = startingfolder.Items
    
    Dim filteredItems As Outlook.Items = Nothing
    
    Dim stringaRicerca As String = "@SQL=" & PR_ATTACH_FILENAME & " ci_phrasematch 'daticert.xml'"
    
    filteredItems = folderitems.Restrict(stringaRicerca)

    The code is working in Outlook 2010, but if I use it in Outlook 2007 it returns zero items.

    Do you know the reason for this beahviour? Or, there is an alternative way to make the same search with a DASL filter?


    • Edited by Klaud76 Wednesday, May 29, 2013 7:00 AM
    Wednesday, May 29, 2013 6:57 AM

Answers

  • I am surprised it works in any version of Outlook. Could be an artifact of how Windows Search works.

    On the low (MAPI) level, to search on attachment name, you would need to create a subrestriction (RES_SUBRESTRICTION) on attachments (PR_MESSAGE_ATTACHMENTS). That restriction would then contain another restriction on the attachment properties, e.g. PR_ATTACH_LONG_FILENAME, PR_ATTACH_EXTENSION, etc.

    If using Redemption is an option, specifying Attachments in a SQL query (RDOItems.Find/Restrict or MAPITable.ExecSQL) will create a PR_MESSAGE_ATTACHMENTS restriction with an OR subrestriction on PR_ATTACH_LONG_FILENAME, PR_ATTACH_EXTENSION, PR_DISPLAY_NAME


    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 29, 2013 2:38 PM

All replies

  • I am surprised it works in any version of Outlook. Could be an artifact of how Windows Search works.

    On the low (MAPI) level, to search on attachment name, you would need to create a subrestriction (RES_SUBRESTRICTION) on attachments (PR_MESSAGE_ATTACHMENTS). That restriction would then contain another restriction on the attachment properties, e.g. PR_ATTACH_LONG_FILENAME, PR_ATTACH_EXTENSION, etc.

    If using Redemption is an option, specifying Attachments in a SQL query (RDOItems.Find/Restrict or MAPITable.ExecSQL) will create a PR_MESSAGE_ATTACHMENTS restriction with an OR subrestriction on PR_ATTACH_LONG_FILENAME, PR_ATTACH_EXTENSION, PR_DISPLAY_NAME


    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 29, 2013 2:38 PM
  • Hi Dmitry,

    Would you mind provide a sample DASL Query for searching by attachment file name? 

    Thanks in advance

    Thursday, March 5, 2020 8:32 AM
  • In OOM? You cannot do that since Items.Find/Restrict does not create sub-restrictions on the attachments, but Redemption does.

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

    Thursday, March 5, 2020 7:26 PM