c# - 使用 C# 从 Lotus Notes 电子邮件中提取/导出附件

标签 c# export extract lotus-notes

我需要将 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);
                }
            }
        }

最佳答案

您不需要使用 $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);
        }
    }

关于c# - 使用 C# 从 Lotus Notes 电子邮件中提取/导出附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1446633/

相关文章:

python - 在 Pandas 数据框中使用正则表达式提取和替换子字符串

r - 将一列中的字符串拆分为两列

c# - HttpWebResponse.ReadTimeout - 不支持超时?

mysql - 将 mySQL 表导出到 OpenOffice 电子表格

c# - 从句子列表中获取最长公共(public)子字符串

c# - 如何创建 CSV Excel 文件 C#?

oracle - 将查询结果导出到一组 INSERT 语句?

java - 从整数值中提取个位和十位

java - C# 数据到 Java

c# - 选择组合框时的事件