none
Outlook Addin (Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))) Error while deleting .vcf file RRS feed

  • Question

  • Hi,

    I am adding a contact thru Right Clicking a Outlook contact --> Forward Contact--> As a Business Card. . This will add a .vcf file as a attachment and a embedded image in the mail body. when user clicks my Addin i have to delete the .vcf attachment and provide a custom link to the user.

    Now the problem is when i try to delete the attachment i am getting this error "Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))"

    Here is my code for deleting the attachment.

    private void RemoveAttachedFiles(Microsoft.Office.Interop.Outlook.Inspector theWindow)
            {
                Microsoft.Office.Interop.Outlook.MailItem msg = theWindow.CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;
                try
                {
                    msg.Save();
                }
                catch
                {
                }
                Redemption.RDOSession rSession = new Redemption.RDOSession();
                rSession.MAPIOBJECT = msg.Application.Session.MAPIOBJECT;
                Redemption.RDOMail rMail = rSession.GetMessageFromID(msg.EntryID);
                for (int i = rMail.Attachments.Count; i >= 1; i--)
                {
                    if ((rMail.Attachments[i].Type == Redemption.rdoAttachmentType.olByValue) && (!rMail.Attachments[i].Hidden))
                    {
                        foreach (Outlook.Attachment attachment in msg.Attachments)
                        {
                            if (attachment.FileName == rMail.Attachments[i].FileName)
                            {
                                attachment.Delete();
                                break;
                            }
                        }
                    }
                }
            }

    Any Suggestion ? ?

    Thanks in advance. .

    Monday, October 12, 2015 7:09 AM

Answers

  • Outlook Version: 15.0.4753.1003

    According to your description, I have made a sample to try to reproduce your issue, unfortunately, I can't.

    1.     Contact --> Forward Contact--> As a Business Card

     

    2.     Delete .vcf file through custom Ribbon Button

     

    3.     Success deleting .vcf file

     

    This is my sample, you could refer to below code:

    Outlook.MailItem mailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem as Outlook.MailItem;
    
    foreach (Outlook.Attachment attachment in mailItem.Attachments)
    
    {
    
         if (attachment.FileName.Contains(".vcf"))
    
         {
    
             attachment.Delete();
    
         }
    
    }
    

    So I suggest you could run this Outlook add-in within another machine or provide more information, for example screenshot, Outlook version, that will help us reproduce and resolve your issue.

    Thursday, October 22, 2015 10:00 AM

All replies

  • Do you get this error on the very first attachment you are trying to delete? Or on a second or third one?

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

    Monday, October 12, 2015 7:13 AM
  • Hi,

    Its First attachment in the MailItem.Attachments. .

    • Edited by GT Mani Monday, October 12, 2015 7:23 AM
    Monday, October 12, 2015 7:18 AM
  • Hello,

    Did you try to use the Outlook object model? Do you get any exception in that case?

    Monday, October 12, 2015 7:24 AM
  • Hi,

    I tried Outlook object model too and i am getting the same Error, ,

    Monday, October 12, 2015 7:40 AM
  • What code exactly did you try? And what property or method fires the exception?
    Monday, October 12, 2015 8:10 AM
  • I 've tried the below code also.

    Microsoft.Office.Interop.Outlook.MailItem msg = theWindow.CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;

    SafeMailItem safeMail = RedemptionLoader.new_SafeMailItem();
                safeMail.Item = msg;

                for (int i = safeMail.Attachments.Count; i >= 1; i--)
                {
                    Redemption.Attachment a = safeMail.Attachments[i];
                    string strContentId = a.Fields[(int)MAPITags.PR_ATTACH_CONTENT_ID] as string;
                    if (strContentId != null && strContentId.Trim().Length > 0)
                        continue;
                    msg.Attachments[i].Delete();
                 }

    Monday, October 12, 2015 8:51 AM
  • The Outlook object model doesn't provide the SafeMailItem class.

    Try to use the OOM only and let me know your results. Why do you need to use Redemption classes for that taks?

    Monday, October 12, 2015 10:53 AM
  • Hi,

    i tried the below code even then i am getting the same error, ,as i am new to outlook plugin i am not sure where i am going wrong. .

    i don't have any issues in deleting all other attachment except these ".vcf" file added thru contacts. 

    Please let me know if you need any more info on the same, ,

    Microsoft.Office.Interop.Outlook.MailItem msg = theWindow.CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;

    foreach (Outlook.Attachment attachment in msg.Attachments)
                {
                    if (attachment.FileName.Contains(".vcf"))
                    {
                        attachment.Delete();
                    }
                }

    Regards

    Mani

    Monday, October 12, 2015 11:31 AM
  • Mani,

    First of all, you need to use the for loop instead.

    You need to decrease the counter with each iteration because the attachments is deleted. For example, a raw sketch:

    for ( int i = attachments.Count;i>=attachments.Count;i--)


    Monday, October 12, 2015 12:26 PM
  • Hi,

    I am getting the same exception still, ,

    FYI, ,

    This exception comes only if i do Right Clicking a Outlook contact --> Forward Contact--> As a Business Card, ,

    If i save the outlook contact as Business Card and if i drag and drop then i don't get any Exception while deleting that attachment, ,

    Tuesday, October 13, 2015 5:09 AM
  • So, the OOM code works correctly for other attachments, right?

    What OOM code exactly do you have now?

    Tuesday, October 13, 2015 6:12 AM
  • yeah, its deleting other files without any exception.

    Here's my Code.

    Microsoft.Office.Interop.Outlook.MailItem msg = theWindow.CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;

    for (int i = msg.Attachments.Count; i >= 1; i--)
    {
    msg.Attachments[i].Delete();
    }

    Tuesday, October 13, 2015 6:40 AM
  • What method or property fires the exception?

    I'd suggest breaking the chain of property and method calls and declaring them on separate lines of code. Thus, you will be able to find what property or method exactly fires the exception.

    Tuesday, October 13, 2015 7:27 AM
  • Delete Method fires the exception, ,

    for (int i = msg.Attachments.Count; i >= 1; i--)
    {

    msg.Attachments[i].Delete(); //Exception occurs in this line
    }

    Tuesday, October 13, 2015 10:00 AM
  • And what property or method fires the exception?
    Tuesday, October 13, 2015 11:25 AM
  • Outlook Version: 15.0.4753.1003

    According to your description, I have made a sample to try to reproduce your issue, unfortunately, I can't.

    1.     Contact --> Forward Contact--> As a Business Card

     

    2.     Delete .vcf file through custom Ribbon Button

     

    3.     Success deleting .vcf file

     

    This is my sample, you could refer to below code:

    Outlook.MailItem mailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem as Outlook.MailItem;
    
    foreach (Outlook.Attachment attachment in mailItem.Attachments)
    
    {
    
         if (attachment.FileName.Contains(".vcf"))
    
         {
    
             attachment.Delete();
    
         }
    
    }
    

    So I suggest you could run this Outlook add-in within another machine or provide more information, for example screenshot, Outlook version, that will help us reproduce and resolve your issue.

    Thursday, October 22, 2015 10:00 AM