HRESULT Exception saving attachments

  • Thread starter Thread starter Lee Moore
  • Start date Start date
L

Lee Moore

The following code gives me an "Exception from HRESULT: 0xC6204005" or
"Exception from HRESULT: 0xCA404005" error. I have tried adjusting the path
but no luck. Everything looks valid to me. The only code that is not
directly from MS is the declaration for the mailbox, oMailbox. I could not
figure out the exact object to use, so I just used a generic Object and made
the assignment. Any help would be most appreciated.



Dim oApp As New Outlook.Application

Dim oNS As Outlook.NameSpace

oNS = oApp.GetNamespace("MAPI")

Dim oMailbox As Object

'Retrieve an Item that has custom and built-in properties

Dim oFolder As Outlook.MAPIFolder

Dim oMsg As Outlook.MailItem

Dim oAttach As Outlook.Attachment

Dim dtParts() As String

Dim fn As String

Try



oMailbox = oNS.Folders.Item("Mailbox - Lee Moore")

oFolder = oMailbox.Folders("EnrSumm")



For Each oMsg In oFolder.Items

For Each oAttach In oMsg.Attachments

dtParts = Split(Microsoft.VisualBasic.Left(oMsg.CreationTime,
Len(oMsg.CreationTime) - (Len(oMsg.CreationTime) - InStr(oMsg.CreationTime,
" "))), "/")

If Len(dtParts(0)) < 2 Then

dtParts(0) = "0" & dtParts(0)

End If

If Len(dtParts(1)) < 2 Then

dtParts(1) = "0" & dtParts(1)

End If

fn = "c:\\enrsumm\\" & dtParts(0) & dtParts(1) & dtParts(2) & ".tgz"

MsgBox(fn)

oAttach.SaveAsFile(fn)

Next

Next

Catch ex As Exception

MsgBox(ex.Message)

End Try
 
How does the fn variable look like before you call SaveAsFile?
Why are you using double slash "\\" in your VB code? It is not C/C++/C#...

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
The fn variable is an empty string to start. The \\ was just a last ditch
effort to solve my dilema. It wan initially a single \.
 
The variable fn is set to "" just before the call to Attachment.SaveAsFile.
The attachment is a .tgz file. It's sort of wierd. I see no anomalies that
would make it not work and HRESULT errors are so non-specific that it makes
things difficult to troubleshoot.
Thanks,
Lee
 
Hi Lee sorry to chime in late here but I just started browsing this
newsgroup. Before you try anything else, check that your temporary
attachment folder is not "full". What I mean is, whenever you work with
attachments, Outlook saves a temporary copy to a location that looks like:

C:\Documents and Settings\Your Name\Temporary Internet
Files\OLK###\SomeAttachment (1).ext
and it will go all the way up to SomeAttachment (99).ext and then give up.

So if you have been debugging your app alot, you may have 100 copies of that
attachment in the temp dir. I have not figured out why Outlook does not
clean these up on its own but I've resorted to cleaning them up myself on
the startup of the appdomain.

You will need to use the command prompt to get to that folder and the exact
location can be determined by looking at the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security

In the following value: OutlookSecureTempFolder.

Sorry if this has been suggested before but I only have the partial thread.
 
Maybe I am missing something, but why do you set fn to "" just before
calling
oAttach.SaveAsFile(fn)?
Wouldn't you want to specify the fully qualified path to where teh
attachment must be saved???
Looking at your source code, it is anything but "".

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I misunderstood your question. I thought you meant before I assigned the
path. Here is the actual assignment...

fn = "c:\enrsumm\" & dtParts(0) & dtParts(1) & dtParts(2) & ".tgz"
 
Voila!!!!! I never would have guessed. I still have the problem of the fact
that I am trying to save 175 daily updates of a single file from messages in
a folder. But easily enough to remedy. Thanks for your well-timed answer. I
was about ready to have a part-timer save each attachment individually. :)
 
Glad I could be of assistance. That was the worst bug i ever ran into and it
took forever to find it. The way I came across it by the way was using
Filemon by www.sysinternals.com

Whenever I start my add in, I run a cleanup task on that folder which
deletes those files. Also, I have created a wrapper class in C# called
OutlookAttachmentStream that derives from FileStream and on Dispose, it
cleans up the temp file(s) that were created. Just some ideas on how you can
work around it.
 
Yes, I saw that code, but I was curious about the values of dtParts(0) etc.
Just trying to make sure you didn't have invalid characters (like ":' etc).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top