【问题标题】:Extract/Export attachements from Lotus Notes Email using C#使用 C# 从 Lotus Notes 电子邮件中提取/导出附件
【发布时间】:2009-09-18 20:20:02
【问题描述】:

我需要将 Lotus Notes 电子邮件附件提取/导出到文件系统中。为此,我编写了以下方法,但每次我在 foreach 行收到错误(NotesItem nItem in items).. 谁能告诉我我做错了什么..

谢谢 贾瓦林

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

        NotesDatabase NotesDb = session.GetDatabase("", "C:\\temps\\lotus\\sss11.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);
                }
            }
        }

【问题讨论】:

    标签: c# export extract lotus-notes


    【解决方案1】:

    您不需要使用 $File 项来获取附件名称。相反,您可以使用 NotesDocument 类的 HasEmbedded 和 EmbeddedObject 属性。

    public void GetAttachments()
        {
        NotesSession session = new NotesSession();
        //NotesDocument notesDoc = new NotesDocument();
        session.Initialize("");
    
        NotesDatabase NotesDb = session.GetDatabase("", "C:\\temps\\lotus\\sss11.nsf", false); //Open Notes Database
        NotesView inbox = NotesDb.GetView("By _Author");
        NotesDocument docInbox = inbox.GetFirstDocument();
    
        // Check if any attachments
        if (docInbox.hasEmbedded)
        {
            NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.embeddedObjects[0];
    
            if (attachfile != null)
            {
                attachfile.ExtractFile("C:\\temps\\export\\" + attachfile.name);
            }
        }
    

    【讨论】:

      【解决方案2】:

      Ed 的解决方案对我不起作用。即使 HasEmbedded 标志为真,我的 Notes 数据库设计似乎也使 EmbeddedObjects 属性为空。所以我将 Ed 和 Jwalin 的解决方案结合起来,修改它们以从 Notes 文档中获取所有附件。

              NotesDocument doc = viewItems.GetNthEntry(rowCount).Document;
              if (doc.HasEmbedded)
              {
                 object[] items = (object[])doc.Items;
                 foreach (NotesItem item in items)
                 {
                    if(item.Name.Equals("$FILE"))
                    {
                       object[] values = (object[])item.Values;
                       doc.GetAttachment(values[0].ToString()).ExtractFile(fileSavePath + values[0].ToString());
                    }
                 }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-15
        • 2014-10-19
        • 1970-01-01
        相关资源
        最近更新 更多