如何从“$ File”项中获取附件值? 使用C#(Lotus Notes)

我试图访问附件名称forms“$ File”(Lotus Notes)。

NotesView inbox = _serverDatabase.GetView("($Inbox)"); NotesDocument docInbox = inbox.GetFirstDocument(); NotesItem file = docInbox.GetFirstItem("$File"); String fileType = file.type.ToString(); 

(获取包含附件的邮件的fileType值“ATTACHMENT”)

我没有得到解决方案:

如何从Notes邮件访问附件?

我得到了解决方案:

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

但在这里,我只获得了第一个附件价值。 任何人都可以帮助我吗?

尝试这样的事情:

  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

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


嗨Preeti,

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

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

玩笑

您的上述代码段对我非常有帮助。 所以,我试着保存所有附件,最后找到了下面的解决方案。

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