msoutlook.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error deleting second attach from RTF Msg w/ Outlook 2007

 
Post new topic   Reply to topic    msoutlook.org Forum Index -> Outlook Programs Add-Ins
Author Message
Byron



Joined: 28 Sep 2007
Posts: 4

PostPosted: Thu Sep 06, 2007 3:06 pm    Post subject: Error deleting second attach from RTF Msg w/ Outlook 2007 Reply with quote

I get an error, 0x80030002 "%1 could not be found.", when I try to
delete the second attachment from an rtf email message only in Outlook
2007. The first attachment gets processed with no problems. I've
tried getting a new Outlook::AttachmentsPtr and a new
Outlook::AttachmentPtr with no luck. The same code works for HTML and
Plain Text for Outlook 2007 as well as HTML, Plain Text, and RTF for
Outlook 2002 and 2003. Below is a snippet of code. Thanks.

pAttachment = pAttachments->Item(1);

m_csInputFile = m_csOutputPathFile = filepath;

originalFilename = (TCHAR*) pAttachment->GetFileName();

m_csInputFile += originalFilename;
m_csOutputPathFile += outfilename;

//Lets try and delete the files just in case the same filename exists
in the temp dir.
DeleteFile(m_csOutputPathFile);
DeleteFile(m_csInputFile);

BSTR bstr = m_csInputFile.AllocSysString();

if (FAILED(pAttachment->SaveAsFile(bstr)))
{
// If we can't save the attachment, we can't encrypt.
CString errMsg;
errMsg.Format(_T("An error was encountered when trying to encrypt
attachment %s.-*"), originalFilename);
AfxMessageBox(errMsg);
throw;
}
SysFreeString(bstr);

// It fails here on the second iteration.
if (FAILED(pAttachment->Delete()))
{
// If we can't remove the "clear text" attachment, we can't send.
CString errMsg;
errMsg.Format(_T("An error was encountered when trying to encrypt
attachment %s."), originalFilename);
AfxMessageBox(errMsg);
}

Archived from group: microsoft>public>outlook>program_addins
Back to top
View user's profile Send private message
Byron



Joined: 28 Sep 2007
Posts: 4

PostPosted: Fri Sep 07, 2007 4:14 pm    Post subject: Re: Error deleting second attach from RTF Msg w/ Outlook 200 Reply with quote

Could someone w/ a known good add-in test this out? I've stripped out
all the code in the Send event except for what's neccessary for
deleting attachments and it still fails with 0x80030002 "%1 could not
be found.". Here is what I have in the send event.

case 0xf005: // Send
try
{
Outlook::_MailItemPtr mailPtr = NULL;
mailPtr = m_pItem->GetMailItem();
int attCount = mailPtr->GetAttachments()->GetCount();
for (int i = attCount; i > 0 ; i--)
{
mailPtr->GetAttachments()->Item(i)->Delete();
}
}
catch(...)
{
CString errMsg;
errMsg.Format(_T("An error was encountered when trying to --Delete--
attachment"));
AfxMessageBox(errMsg);
}


On Sep 6, 2:06 pm, Byron wrote:
> I get an error, 0x80030002 "%1 could not be found.", when I try to
> delete the second attachment from an rtf email message only in Outlook
> 2007. The first attachment gets processed with no problems. I've
> tried getting a new Outlook::AttachmentsPtr and a new
> Outlook::AttachmentPtr with no luck. The same code works for HTML and
> Plain Text for Outlook 2007 as well as HTML, Plain Text, and RTF for
> Outlook 2002 and 2003. Below is a snippet of code. Thanks.
>
> pAttachment = pAttachments->Item(1);
>
> m_csInputFile = m_csOutputPathFile = filepath;
>
> originalFilename = (TCHAR*) pAttachment->GetFileName();
>
> m_csInputFile += originalFilename;
> m_csOutputPathFile += outfilename;
>
> //Lets try and delete the files just in case the same filename exists
> in the temp dir.
> DeleteFile(m_csOutputPathFile);
> DeleteFile(m_csInputFile);
>
> BSTR bstr = m_csInputFile.AllocSysString();
>
> if (FAILED(pAttachment->SaveAsFile(bstr)))
> {
> // If we can't save the attachment, we can't encrypt.
> CString errMsg;
> errMsg.Format(_T("An error was encountered when trying to encrypt
> attachment %s.-*"), originalFilename);
> AfxMessageBox(errMsg);
> throw;}
>
> SysFreeString(bstr);
>
> // It fails here on the second iteration.
> if (FAILED(pAttachment->Delete()))
> {
> // If we can't remove the "clear text" attachment, we can't send.
> CString errMsg;
> errMsg.Format(_T("An error was encountered when trying to encrypt
> attachment %s."), originalFilename);
> AfxMessageBox(errMsg);
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -
Back to top
View user's profile Send private message
Byron



Joined: 28 Sep 2007
Posts: 4

PostPosted: Wed Sep 12, 2007 9:41 am    Post subject: Re: Error deleting second attach from RTF Msg w/ Outlook 200 Reply with quote

Finally found a solution to the problem. Simple call Save on the
MailItem before trying to process the next attachment.

case 0xf005: // Send
try
{
Outlook::_MailItemPtr mailPtr = NULL;
mailPtr = m_pItem->GetMailItem();
int attCount = mailPtr->GetAttachments()->GetCount();
for (int i = attCount; i > 0 ; i--)
{
mailPtr->GetAttachments()->Item(i)->Delete();
mailPtr->Save();
}
}

catch(...)
{
CString errMsg;
errMsg.Format(_T("An error was encountered when trying to --
Delete--
attachment"));
AfxMessageBox(errMsg);

}


On Sep 7, 3:14 pm, Byron wrote:
> Could someone w/ a known good add-in test this out? I've stripped out
> all the code in the Send event except for what's neccessary for
> deleting attachments and it still fails with 0x80030002 "%1 could not
> be found.". Here is what I have in the send event.
>
> case 0xf005: // Send
> try
> {
> Outlook::_MailItemPtr mailPtr = NULL;
> mailPtr = m_pItem->GetMailItem();
> int attCount = mailPtr->GetAttachments()->GetCount();
> for (int i = attCount; i > 0 ; i--)
> {
> mailPtr->GetAttachments()->Item(i)->Delete();
> }}
>
> catch(...)
> {
> CString errMsg;
> errMsg.Format(_T("An error was encountered when trying to --Delete--
> attachment"));
> AfxMessageBox(errMsg);
>
> }
>
> On Sep 6, 2:06 pm, Byron wrote:
>
>
>
> > I get an error, 0x80030002 "%1 could not be found.", when I try to
> > delete the second attachment from an rtf email message only in Outlook
> > 2007. The first attachment gets processed with no problems. I've
> > tried getting a new Outlook::AttachmentsPtr and a new
> > Outlook::AttachmentPtr with no luck. The same code works for HTML and
> > Plain Text for Outlook 2007 as well as HTML, Plain Text, and RTF for
> > Outlook 2002 and 2003. Below is a snippet of code. Thanks.
>
> > pAttachment = pAttachments->Item(1);
>
> > m_csInputFile = m_csOutputPathFile = filepath;
>
> > originalFilename = (TCHAR*) pAttachment->GetFileName();
>
> > m_csInputFile += originalFilename;
> > m_csOutputPathFile += outfilename;
>
> > //Lets try and delete the files just in case the same filename exists
> > in the temp dir.
> > DeleteFile(m_csOutputPathFile);
> > DeleteFile(m_csInputFile);
>
> > BSTR bstr = m_csInputFile.AllocSysString();
>
> > if (FAILED(pAttachment->SaveAsFile(bstr)))
> > {
> > // If we can't save the attachment, we can't encrypt.
> > CString errMsg;
> > errMsg.Format(_T("An error was encountered when trying to encrypt
> > attachment %s.-*"), originalFilename);
> > AfxMessageBox(errMsg);
> > throw;}
>
> > SysFreeString(bstr);
>
> > // It fails here on the second iteration.
> > if (FAILED(pAttachment->Delete()))
> > {
> > // If we can't remove the "clear text" attachment, we can't send.
> > CString errMsg;
> > errMsg.Format(_T("An error was encountered when trying to encrypt
> > attachment %s."), originalFilename);
> > AfxMessageBox(errMsg);
>
> > }- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
Back to top
View user's profile Send private message
Byron



Joined: 28 Sep 2007
Posts: 4

PostPosted: Thu Sep 13, 2007 3:36 pm    Post subject: Re: Error deleting second attach from RTF Msg w/ Outlook 200 Reply with quote

And of course 2 days later I run across the online documentation,
should have looked there instead of using VBAOL10.CHM.

http://msdn2.microsoft.com/en-us/library/aa217214(office.10).aspx

(Last Line on page)
"To ensure consistent results, always save an item before adding or
removing objects in the Attachments collection of the item."


On Sep 12, 8:41 am, Byron wrote:
> Finally found a solution to the problem. Simple call Save on the
> MailItem before trying to process the next attachment.
>
> case 0xf005: // Send
> try
> {
> Outlook::_MailItemPtr mailPtr = NULL;
> mailPtr = m_pItem->GetMailItem();
> int attCount = mailPtr->GetAttachments()->GetCount();
> for (int i = attCount; i > 0 ; i--)
> {
> mailPtr->GetAttachments()->Item(i)->Delete();
> mailPtr->Save();
> }
>
> }
>
> catch(...)
> {
> CString errMsg;
> errMsg.Format(_T("An error was encountered when trying to --
> Delete--
> attachment"));
> AfxMessageBox(errMsg);
>
> }
>
> On Sep 7, 3:14 pm, Byron wrote:
>
>
>
> > Could someone w/ a known good add-in test this out? I've stripped out
> > all the code in the Send event except for what's neccessary for
> > deleting attachments and it still fails with 0x80030002 "%1 could not
> > be found.". Here is what I have in the send event.
>
> > case 0xf005: // Send
> > try
> > {
> > Outlook::_MailItemPtr mailPtr = NULL;
> > mailPtr = m_pItem->GetMailItem();
> > int attCount = mailPtr->GetAttachments()->GetCount();
> > for (int i = attCount; i > 0 ; i--)
> > {
> > mailPtr->GetAttachments()->Item(i)->Delete();
> > }}
>
> > catch(...)
> > {
> > CString errMsg;
> > errMsg.Format(_T("An error was encountered when trying to --Delete--
> > attachment"));
> > AfxMessageBox(errMsg);
>
> > }
>
> > On Sep 6, 2:06 pm, Byron wrote:
>
> > > I get an error, 0x80030002 "%1 could not be found.", when I try to
> > > delete the second attachment from an rtf email message only in Outlook
> > > 2007. The first attachment gets processed with no problems. I've
> > > tried getting a new Outlook::AttachmentsPtr and a new
> > > Outlook::AttachmentPtr with no luck. The same code works for HTML and
> > > Plain Text for Outlook 2007 as well as HTML, Plain Text, and RTF for
> > > Outlook 2002 and 2003. Below is a snippet of code. Thanks.
>
> > > pAttachment = pAttachments->Item(1);
>
> > > m_csInputFile = m_csOutputPathFile = filepath;
>
> > > originalFilename = (TCHAR*) pAttachment->GetFileName();
>
> > > m_csInputFile += originalFilename;
> > > m_csOutputPathFile += outfilename;
>
> > > //Lets try and delete the files just in case the same filename exists
> > > in the temp dir.
> > > DeleteFile(m_csOutputPathFile);
> > > DeleteFile(m_csInputFile);
>
> > > BSTR bstr = m_csInputFile.AllocSysString();
>
> > > if (FAILED(pAttachment->SaveAsFile(bstr)))
> > > {
> > > // If we can't save the attachment, we can't encrypt.
> > > CString errMsg;
> > > errMsg.Format(_T("An error was encountered when trying to encrypt
> > > attachment %s.-*"), originalFilename);
> > > AfxMessageBox(errMsg);
> > > throw;}
>
> > > SysFreeString(bstr);
>
> > > // It fails here on the second iteration.
> > > if (FAILED(pAttachment->Delete()))
> > > {
> > > // If we can't remove the "clear text" attachment, we can't send.
> > > CString errMsg;
> > > errMsg.Format(_T("An error was encountered when trying to encrypt
> > > attachment %s."), originalFilename);
> > > AfxMessageBox(errMsg);
>
> > > }- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Compile Addin for OL 2000 thru 2007 I have an addin for Outlook that works in 2000 thru 2003. It also works in 2007 with a few changes. However, the 2007 version puts the buttons in the Add-Ins tab. I have made changes to customize the Ribbon with my own tab & everything works if I compile

How to add envid,notify and ret parameters to Outlook mail ? I'm writing an application as plugin to Outlook 2003 using VSTO. Now I have a big problem. I tried to add envid,notify and ret parameters to message header (MailItem) but I got stuck. According to SMTP envid and ret must be a

Outlook crashes during shutdown after running operation I have a COM addin (VB6), that had run without error until recently. When the following code is run, the microsoft error reporting window comes up when outlook is closing after the and after the events. Private Sub ExecuteBu

Live Local add-in for Outlook fails install I have Win XP SP2, Office 2003 SP2. I had the beta version of Windows Live Local add-in for Outlook, which stopped working when IE7 was out. So I uninstalled the add-in using Add/Remove programs. The Windows Live Local add-in does not appear in my Add/

Addin will not load in Vista/Outlook 2007 Hello. I have an addin that works fine on XP/Outlook 2007, but once we install it on Vista, it won't load in Outlook 2007. Looking in the Tools --> Trust Center --> Addins, etc., I see the generic message "Not loaded. A runtime error occurred during th
Post new topic   Reply to topic    msoutlook.org Forum Index -> Outlook Programs Add-Ins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group