Difference between attachment displayname and filename

Status
Not open for further replies.

Van Knowles

New Member
Outlook version
Email Account
Exchange Server 2013
Hi. I've looked around the Internet a bit and have seen a lot of examples of Outlook VBA code using Attachment.DisplayName to save email attachments as files. However, my experience is that DisplayName (a) can have characters that are not valid for the Windows file system and (b) DisplayName does not include a file extension when the attachment is another email message (MSG format).

Some limited testing suggests that Attachment.FileName is the better choice because it appears to always be a valid Windows file name and always has an extension.

Does anyone have definitive information about the differences between these two properties of the Attachment object, especially any pitfalls to using FileName?

Thanks!
 
Afaik it depends on which method is used to attach the data. The usual attachment (attached by value) has both properties when you create the email but only the file name on the receiver's side. Still, when you access the DisplayName property, Outlook shows data, so I guess it's showing the file name actually.

If it's an embedded attachment, it has a DisplayName but no file name.

I have never seen that one can attach a file (as opposed to adding, for instance, a contact item) and get different values in DisplayName and FileName. Afaik it's the opposite: Outlook doesn't allow to change the DisplayName so that spammers cannot add an exe file and name it 'jpg'.
 
Just experimenting with different messages and attachments, I found the following:
  1. The DisplayName and FileName are usually the same.
  2. If the attachment is itself an Outlook message (MSG file), then DisplayName shows the subject of the message, which might contain characters not valid for a file name; it also has no extension. FileName shows a valid file name including the MSG extension.
  3. It does not matter whether the attachment is embedded or not. I found a FileName value for both types of attachments. I admit that I did not look at a lot of examples, so maybe there are cases in which there is no FileName value.
My hypothesis is that Outlook always provides a valid file name in the FileName property, but the DisplayName property value depends on the type of attachment and is not always valid as a file name.

What I know is that DisplayName is not always valid as a file name, so I think there are many examples of code (including some provided by Microsoft like this one) that will fail if the attachment is an Outlook message. The resulting name string will have no extension and might have invalid file name characters.

What I do not know for sure is whether FileName always contains a valid file name. I also do not know whether there are other kinds of attachments for which FileName and DisplayName differ.
 
Did you use OutlookSpy to look at the "real" values? If you attach a file, it certainly will have a valid file name. If you attach an Outlook item not from the file system, but directly from Outlook, then the source is not a file, and in that case I would not suppose Outlook to translate anything into a valid file name, however, it adds the file extension to the file name.

So to be sure, always use the FileName property, and ensure yourself it doesn't contain invalid chars.
 
I have been using VBA with checkpoints and displaying the names in the immediate window, so I know exactly what the property values are.

When you attach an email message, Outlook does, in fact, translate the message subject into a valid system file name with .MSG extension. I have observed this.

Yes, I think it would be good practice to verify the characters in the FileName property, even though they seem to be valid when I've looked at them.

Which is back to my original question--whether there is any definitive documentation of these properties.
 
:)

I'm simply saying that the MSDN documentation does not seem to completely describe what is returned by FileName and DisplayName. Which, in my experience, is pretty typical.

I can say definitively that if you use DisplayName as the system file name when saving an attachment, as Microsoft shows in its example code, you will get invalid file names in some situations, and I don't think Microsoft has documented that.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Commodore Difference between Facebook entries in browser vs. people pane Using Outlook 2
Jennifer Murphy Difference between export and archive? Using Outlook 10
V Difference between UserProperties and ItemProperties? Outlook VBA and Custom Forms 4
C Difference between the TabStrip and MultiPage controls?? Outlook VBA and Custom Forms 2
Q Difference between Regular Attachments and Signature Attachments Outlook VBA and Custom Forms 3
T The From field difference in OL 2003 to 2010 Using Outlook 1
C Trying to move messages between imap accounts/folders Using Outlook 5
O How to sync (one way) contacts between two Outlook (exchange) accounts? Using Outlook 0
L Format Lost between Tasks and To Do Using Outlook 0
Commodore Automatic switch between working offline/online Using Outlook 4
J VBA for outlook to compare and sync between calendar Outlook VBA and Custom Forms 1
H Stationery using between OL 2019 and OL 2010 Using Outlook 0
HarvMan Toggle between calendar and email in Outlook 365 Using Outlook 12
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
P Move emails between 2 mailboxes. Using Outlook 0
G Outlook 2016 sync contacts directly between phone and computer using outlook 2016 Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
I Automating message move between folders Outlook VBA and Custom Forms 0
D Move Emails between Folders in Separate Mailbox Outlook VBA and Custom Forms 12
S Moving Emails Between Archive Folders Using Outlook 1
C VBA to Forward e-mails from certain address and between certain times Outlook VBA and Custom Forms 1
J Syncing notes between Outlook 2016/Exchange and Outlook for Android Using Outlook 2
R Trying to extract information between two symbols from outlook subject Using Outlook 2
K Macro to search emails between two time slots on public folders with excel export Outlook VBA and Custom Forms 12
H Sync Contacts between Office 365 and Gmail. Exchange Server Administration 3
I Outlook Contacts and Calenders not syncing between PC, IPhone, and Windows 8.1 tablet Using Outlook 3
N Passing Attachments between forms? Outlook VBA and Custom Forms 2
C Is it possible to have contacts sync real-time between Outlook and iCloud? Using Outlook 1
W Sync categories between Exchange and 2007 Exchange Server Administration 1
S Updating between Smartphone and PC Using Outlook 3
M moving custom field data between outlook and excel? Using Outlook 4
Paul Van Cotthem Is calendar synchronization between Office 2013 and Outlook.com capped by spam or bandwidth limits? Using Outlook.com accounts in Outlook 12
P Sync 2013 calendar between 2 devices -Surface 2 and Desktop using Outlook.com Using Outlook.com accounts in Outlook 8
X When travel between time zones Calendar Daily Items a fixed times vs Meetings? Using Outlook 2
Y Search/list all emails sent between 6pm to 12am in the past 30 days Using Outlook 3
L Outlook 2007 Delete and Paste Between Fields Using Outlook 25
X VBA: Confused with variables between ThisOutlookSession and UserForm Using Outlook 1
R Slow Calendar Synch Between Outlook 2013 and iCloud Using Outlook 5
B Syncing Outlook 2010 between two computers Using Outlook 1
F I want simple syncing between my 3 PCs and Android devices. Using Outlook 1
S Syncing Email Between Computers Using Outlook 6
S Share between 2000 and 2010 Using Outlook 3
A Network Permissions for sharing calenders between exchange severs Using Outlook 1
S Calendar sharing problmes between Outlook 2007 & 2010 Exchange Server Administration 0
R Share ost between connector and exchange cache mode = "everything everywhere" Using Outlook 3
J switching BCM between to computers BCM (Business Contact Manager) 1
B Copying data between atbs in a custom form Outlook VBA and Custom Forms 4
P Public folder replication between Exchange 2007 and Exchange 2010 Exchange Server Administration 11
T Categories not persisted between sessions in Outlook 2007 Outlook VBA and Custom Forms 8
L Programmatically moving between pages in a form Outlook VBA and Custom Forms 2

Similar threads

Back
Top