tags:

views:

1839

answers:

4

Hi,

I am trying to access Attachment names form "$File" (Lotus Notes).

NotesView inbox = _serverDatabase.GetView("($Inbox)"); NotesDocument docInbox = inbox.GetFirstDocument();

NotesItem file = docInbox.GetFirstItem("$File");

String fileType = file.type.ToString();

( getting fileType value "ATTACHMENT" for mail containing attachments)

I am not getting solution given in:

http://stackoverflow.com/questions/1361695/how-to-access-attachments-from-notes-mail

+2  A: 

Hi Preeti,

Try something like this:

    NotesView inbox = _serverDatabase.GetView("($Inbox)"); 
    NotesDocument docInbox = inbox.GetFirstDocument();  
    if(docInbox.HasEmbedded ) {
    foreach (NotesEmbeddedObject o in docInbox.EmbeddedObjects) {
        if ( o.Type == 1454 ) {
      o.ExtractFile( "c:\samples\" & o.Source )    
 }
   }
}

Here is a link to Lotus Notes Designer Help - Really good as you can search for Classes etc to find out what options you have.

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.help.domino.designer85.doc/DOC/H%5FWHAT%5FS%5FNEW%5FIN%5FRNEXT%5FCHAP.html

Show you all the methods and properties of various class.


Hi Preeti,

OK from the other code sample you are returning an array:

string fileName = ((object[])nItem.Values) [0].ToString();

Yet you are only selecting the first value, you need to recurse through the collection.

Try something like this.

foreach (object attachment in (object[])nItem.Values)
        {
            NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.GetAttachment(attachment.ToString());

            if (attachfile != null)
            {
                attachfile.ExtractFile("C:\\test\\" + attachment.ToString());
            }

        }

Josh

jj.matthews
Preeti Singh
Ken Pespisa
A: 

I got solution as:

object[] items = (object[])docInbox.Items;

foreach (NotesItem nItem in items)

{

if (nItem.Name == "$FILE") {

 NotesItem file = docInbox.GetFirstItem("$File");   

 string fileName = ((object[])nItem.Values) [0].ToString();

 NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.GetAttachment(fileName);

 if (attachfile != null)
  {
    attachfile.ExtractFile("C:\\test\\" + fileName);
  }

}

But here i am getting only first attachment value. :( Can anyone help me out in this.

Preeti Singh
(moderator flags are not for requesting answers; try clarifying the question; oh, and edit the **question** - don't add questions as answers, and please don't keep asking new copies of the same question).
Marc Gravell
same question? Marc can you please tel me where i repeated my question? ( just need to know..may be i didn't understand that). About posting question as answer: In current question i just wanted to share my solution with people who are facing same problem i faced ( can you please provide me any other alternative in this case? )
Preeti Singh
A: 

I created one method but getting error could you please tell me what is the wrong


    public void GetAttachments()
    {
        NotesSession session = new NotesSession();
        //NotesDocument notesDoc = new NotesDocument();
        session.Initialize("");

        NotesDatabase NotesDb = session.GetDatabase("", "C:\\temps\\lotus\\voices2.nsf", false); //Open Notes Database
        NotesView inbox = NotesDb.GetView("By _Author");
        NotesDocument docInbox = inbox.GetFirstDocument();
        object[] items = (object[])docInbox.Items;
        foreach (NotesItem nItem in items)
        {

            //NotesItem nItem = (NotesItem)o1;
            if (nItem.Name == "$FILE")
            {
                NotesItem file = docInbox.GetFirstItem("$File");
                string fileName = ((object[])nItem.Values)[0].ToString();
                NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.GetAttachment(fileName);

                if (attachfile != null)
                {
                    attachfile.ExtractFile("C:\\temps\\export\\" + fileName);
                }
            }
        }
jk
A: 

Hi,

Your above code snippet is very helpful to me. So, I tried the to save all attachments and finally found the below solution.

            NotesView nInboxDocs = NDb.GetView("$Inbox");
            NDoc=nInboxDocs.GetFirstDocument();
            while (NDoc != null)
            {
                if (NDoc.HasEmbedded && NDoc.HasItem("$File"))
                {
                    // To save only first attachment //
                    //pAttachment = ((object[])NDoc.GetItemValue("$File"))[0].ToString();
                    //pAttachment = CurItem.ToString();
                    //NDoc.GetAttachment(pAttachment).ExtractFile(@"C:\Documents and Settings\Administrator\Desktop\" + pAttachment);

                    // To save all attachment //
                    object[] AllDocItems = (object[])NDoc.Items;
                    foreach (object CurItem in AllDocItems)
                    {
                        NotesItem nItem = (NotesItem)CurItem;
                        if (IT_TYPE.ATTACHMENT == nItem.type)
                        {
                            pAttachment = ((object[])nItem.Values)[0].ToString();
                            NDoc.GetAttachment(pAttachment).ExtractFile(@"C:\Documents and Settings\Administrator\Desktop\" + pAttachment);
                        }
                    }
                }
                NDoc = nInboxDocs.GetNextDocument(NDoc);
            }