tinks
tinks

Reputation: 129

Getting exception while extracting Attachment from Lotus Notes(.nsf) file through C# code

Can someone please help me as I am getting below exception while casting the itemA object into Notesitem in foreach loop.

Unable to cast COM object of type 'System.__ComObject' to interface type 'Domino.NotesItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2913158A-2EED-1069-BF5D-00DD011186B7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). at WindowsApplication2.Form1.btnSearch_Click(Object sender, EventArgs e) in C:\WindowsApplication2\WindowsApplication2\Form1.cs:line 319}

I am using Interop.Domino.dll with code :

        NotesSession session = new NotesSession();
        session.Initialize("XXXXXX");
        try
        {
            NotesDatabase NotesDb = session.GetDatabase("", "C:\LotusFiles\\XYZ.nsf", false);

            if (NotesDb == null)
            {
                //System.Console.WriteLine("Can not connect to server.");
            }
            else
            {
                //System.Console.WriteLine("Connected");
            }

            Domino.NotesDocumentCollection col = NotesDb.AllDocuments;
            for (int i = 0; i < col.Count; ++i)
            {
                Domino.NotesDocument doc = col.GetNthDocument(i);

                if (doc.HasEmbedded)
                {
                    object[] itemsA = (object[])doc.Items;
                    foreach (NotesItem item in itemsA)
                    {
                        if (item.Name.Equals("$FILE"))
                        {
                            object[] values = (object[])item.Values;
                            //doc.GetAttachment(values[0].ToString()).ExtractFile(fileSavePath + values[0].ToString());
                        }
                    }
                }



            }

Upvotes: 0

Views: 822

Answers (1)

tinks
tinks

Reputation: 129

got it resolved phewwwwwwww... the Interop.Domino.dll was corrupt in my case, all the people facing this issue please don't download Interop.Domino.dll from the internet rather go to Refrence-->Add Refrence-->COM-->Locate Lotus Domino Objects and Bingo !!!

Upvotes: 1

Related Questions