【问题标题】:How to get Attachment value from "$File" Item? using C# (Lotus Notes)如何从“$File”项中获取附件值?使用 C# (Lotus Notes)
【发布时间】:2009-09-16 07:45:58
【问题描述】:

我正在尝试从“$File”(Lotus Notes)访问附件名称。

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

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

 String fileType = file.type.ToString(); 

(获取包含附件的邮件的文件类型值“附件”)

我没有得到解决方案:

How to Access attachments from Notes mail?

我得到了解决方案:

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);
      }
 } 

但在这里我只得到第一个附件值。 谁能帮我解决这个问题?

【问题讨论】:

  • “版主标志”用于行政支持,而不是对紧急问题的回答。

标签: c# lotus-notes


【解决方案1】:

试试这样的:

    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 )    
    }
   }
}

这里是 Lotus Notes Designer 帮助的链接 - 非常好,因为您可以搜索类等以找出您有哪些选项。

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.help.domino.designer85.doc/DOC/H_WHAT_S_NEW_IN_RNEXT_CHAP.html

向你展示各种类的所有方法和属性。


嗨,普瑞蒂,

从您返回数组的其他代码示例中确定:

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

然而你只选择了第一个值,你需要遍历集合。

试试这样的。

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

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

        }

乔什

【讨论】:

  • 嗨 Mathews,我收到以下错误::( 错误 1:foreach 语句无法对“object”类型的变量进行操作,因为“object”不包含“GetEnumerator”错误 2 的公共定义: Domino.NotesEmbeddedObject'不包含'Type'的定义错误3:运算符'&'不能应用于'string'和'string'类型的操作数请帮我解决。
  • 或许你可以先使用 NotesEmbeddedObject[] embobjs = docInbox.EmbeddedObjects; 得到 NotesEmbeddedObjects 的数组。然后使用 foreach 循环或 for 循环来处理 embobjs 数组中的所有对象。此外,第三个错误是因为 & 运算符在 C# 中的含义与在 Lotusscript 中的含义不同。您需要使用 + 运算符来连接字符串。
【解决方案2】:

您上面的代码 sn-p 对我很有帮助。所以,我尝试保存所有附件,终于找到了以下解决方案。

            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);
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多