XADM: CDO AddAttachment Fails on E-mail Attachment When a Colon (:) Is in Attachment Subject (301339)



The information in this article applies to:

  • Microsoft Exchange 2000 Server
  • Microsoft Exchange Server 5.5

This article was previously published under Q301339

SYMPTOMS

Your messaging program may stop responding and you may receive the following error message:
-2147024773: The filename, directory name, or volume label syntax is incorrect.

CAUSE

This issue may occur when the following conditions are true:
  • Your program uses the AddAttachment method of the CDO.Message object to attach a message that is located in the Web store to a new message.
  • The subject portion of the URL that points to the message that the application tries to attach contains a colon (:) or another special character.

WORKAROUND

To work around this issue, double-encode all extended characters in the URL path that is passed to the ExOleDB (Exchange OLE DB) provider or to the AddAttachment function. The following table lists special characters that must be double-encoded:
Character  URL Encoded   Double-Escaped
---------------------------------------
?          %3f           %253f
~          %7e           %257e
#          %23           %2523
:          %3a           %253a
;          %3b           %253b
&      %26           %2526
+          %2b           %252b
*          %2a           %252a
"          %22           %2522
>       %3c           %253c
<       %3e           %253e
|          %7c           %257c
%          %25           %2525
/          %2f           %252f

For example, use the following code to double-escape a colon:
If InStr(1, szSubj, ":") Then
  szSubj = Replace(szSubj, ":", "%3A")
  Err.Clear
  oInMsg.DataSource.Open szURI
  szURI = IMbx.Inbox & "/" & szSubj & ".EML"
  Err.Clear
  'Double escape the colon and attach the message 
  szURI = Replace(szURI, "%3A", "%253A")
  Set oAttach = oOut2Msg.AddAttachment(szURI)
  oOut2Msg.Send
End If

MORE INFORMATION

When you encode a special character in a URL string that you pass to ExOLEDB or to the AddAttachment function, you must express it in the equivalent ASCII code (hexadecimal) preceded by the percent sign (%). Because the percent sign (25hex) is also a special character, it too must be expressed in the equivalent ASCII code (with the percent sign). For example, the colon (:) would be expressed as %253a, where %25 represents the percent sign, and 3a represents the colon. This process of encoding a character two times is frequently referred to as double-encoding a character.

Modification Type:MajorLast Reviewed:8/20/2003
Keywords:kbprb KB301339 kbAudDeveloper