简体   繁体   English

如何使用C#编辑NSF文件?

[英]How to Edit NSF file using c#?

I want to programaticaly change some values to NSF item and then want to save it.(ie to edit NSF File and then save the editions) 我想以编程方式将一些值更改为NSF项目,然后保存它。(即,编辑NSF文件,然后保存版本)

for example: 例如:

I want to set Sender name of all mails to "preeti@abc.com".(Using Domino.dll). 我想将所有邮件的发件人名称设置为“ preeti@abc.com”。(使用Domino.dll)。

Solution I tried: (Swaping of To and From values) 我尝试的解决方案:(交换To和From值)

String Temp_From = ((object[])docInbox.GetItemValue("From"))[0] as String; 字符串Temp_From =((object [])docInbox.GetItemValue(“ From”))[0]作为字符串; String Temp_SendTo = ((object[])docInbox.GetItemValue("SendTo"))[0] as String; 字符串Temp_SendTo =((object [])docInbox.GetItemValue(“ SendTo”))[0]作为字符串; docInbox.ReplaceItemValue("From", Temp_SendTo); docInbox.ReplaceItemValue(“ From”,Temp_SendTo); docInbox.ReplaceItemValue("SendTo", Temp_From); docInbox.ReplaceItemValue(“ SendTo”,Temp_From); docInbox.Save(true, false, false); docInbox.Save(true,false,false);

/* Applied for following fields also: / *也适用于以下字段:

For From: AltFrom,DisplayFrom,DisplayFrom_2,dspFrom,ForwardedFrom,INetFrom,tmpDisplayFrom 对于发件人:AltFrom,DisplayFrom,DisplayFrom_2,dspFrom,ForwardedFrom,INetFrom,tmpDisplayFrom

For To : displaySendTo,EnterSendTo,Envelope_to,tmpDisplaySendTo 收件人:displaySendTo,EnterSendTo,Envelope_to,tmpDisplaySendTo

Also Tried for saving : docInbox.Save(true, true, true); 还尝试保存:docInbox.Save(true,true,true); */ * /

In above code after successful editing changes values are not reflected in Nsf File. 在上面的代码中,成功编辑更改后,值未反映在Nsf文件中。 But when i am reading edited Nsf (copying modified file on different location ) file programatically it is showing changed values.(Why changes are not visible here ?) 但是当我以编程方式读取编辑的Nsf文件(将修改后的文件复制到其他位置)时,它显示的是更改后的值(为什么更改在此处不可见?)

The "Programming Guide, Volume 2: LotusScript/COM/OLE Classes" can be found here: http://www-12.lotus.com/ldd/doc/uafiles.nsf/docs/DESIGNER70/ 可以在这里找到“编程指南,第2卷:LotusScript / COM / OLE类”: http : //www-12.lotus.com/ldd/doc/uafiles.nsf/docs/DESIGNER70/

As brief summary, though, once you have a handle to a Document, you can iterate over all of the existing fields ("items") on that document using the Items property; 不过,作为简要概述,一旦有了Document的句柄,就可以使用Items属性遍历该文档上的所有现有字段(“项目”)。 and you can update a given field on that document using the ReplaceItemValue and/or AppendItemValue methods. 并且您可以使用ReplaceItemValue和/或AppendItemValue方法更新该文档上的给定字段。

Are you checking the result with the Notes client? 您是否正在使用Notes客户端检查结果? I guess this behavior could be explained by the client's rather aggressive caching. 我猜这种现象可以由客户端相当积极的缓存来解释。 Try removing the file cache.ndk from the data directory before you check the result of your program. 在检查程序结果之前,请尝试从数据目录中删除文件cache.ndk

Also, a Notes "Item" typically contains an array of values - your approach to swapping the SendTo and From fields will loose data if for example a mail has been sent to several people. 另外,Notes“项目”通常包含一个值数组-如果例如已将邮件发送给多个人,则交换SendToFrom字段的方法将丢失数据。 Try copying the entire object[] instead. 尝试复制整个object[]

I did that once. 我做了一次。

You have to add a new reference to your project and choose 'COM' in the 'Add Reference' dialog. 您必须为项目添加一个新引用,然后在“添加引用”对话框中选择“ COM”。 Find the component named 'Lotus Domino Objects' in the list and add it. 在列表中找到名为“ Lotus Domino Objects”的组件并将其添加。 You will see a new reference called 'Domino' added to your project. 您将在项目中看到一个名为“ Domino”的新引用。 That COM component is installed by the Lotus Notes Client. 该COM组件由Lotus Notes客户端安装。 You must have it in your development machine, and you will have to have it installed when you run your application too. 您必须在开发计算机中安装它,并且在运行应用程序时也必须安装它。

From that point you can use most of the classes you have available when developing with lotusscript within NotesDesigner. 从那时起,您可以使用在NotesDesigner中使用Lotusscript开发时可以使用的大多数类。

Add an appropriate 'using' statement: 添加适当的“使用”语句:

using Domino;

Create a notes session: 创建一个笔记会话:

NotesSession session = new NotesSession();
session.Initialize("mypassword");
//this uses your current Notes location and id.
//i think you can use session.Initialize("") if notes is already running and you are already logged in.

Get a database: 获取数据库:

NotesDatabase notesDb = session.GetDatabase("server", "database", false);

Get some documents, for example: today's appointments (if the database you opened is your mail.nsf) 获取一些文档,例如:今天的约会(如果您打开的数据库是mail.nsf)

NotesDocumentCollection col = null;
try { col = notesDb.Search("Form = \"Appointment\" & StartDate = @Today", null, 0); }
catch (Exception e) { }

Iterate through your collection: 遍历您的集合:

if (null != col)
{
    NotesDocument doc = col.GetFirstDocument();
    while (doc != null)
    {
        //do your magic tricks
        doc = col.GetNextDocument(doc);
    }
}    

One problem I noticed with this interface: there is no session.Close() method nor anything similar, and my sessions were not being closed in the server once the GC collected the C# object. 我注意到此接口的一个问题:没有session.Close()方法或类似的东西,并且一旦GC收集了C#对象,服务器中的会话就没有关闭。 Once I opened a new NotesSession(), it stayed alive in the domino server as long as my c# thread was alive. 一旦我打开了一个新的NotesSession(),只要我的c#线程仍在运行,它就会在Domino服务器中保持运行。 To solve that problem, I had to create background threads and only instantiate new NotesSession() objects from within the threads. 为了解决该问题,我不得不创建后台线程,并且仅在线程中实例化新的NotesSession()对象。 The threads also had to be setup with STA apartment mode before being started. 在启动之前,还必须使用STA公寓模式设置线程。

Thread thread = new Thread(new ThreadStart(MyFunctionThatInstantiatesNewNotesSessions));
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();
thread.Join();

I'm not sure if this problem is really a problem in the interface, or something else i did wrong in my code. 我不确定这个问题是否真的是界面中的问题,或者我在代码中做错了其他事情。 But if someone is facing that problem: threads are the way I fixed it. 但是,如果有人遇到了这个问题:线程是我解决问题的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#加密和解密NSF文件 - Encrypting and Decrypting NSF file using C# 如何使用C#以编程方式将内容(邮件,联系人等)添加到NSF文件? - How to programatically add contents(mail,contacts e.t.c) to NSF File using c#? 使用C#从nsf文件(例如mail / usermail.nsf)列出收件箱,发件箱,日历,新闻等 - Listing inbox,outbox,calendars,journal e.t.c. from nsf file (eg: mail/usermail.nsf) using C# 使用 interop.domino.dll c# 在 .nsf 文件中创建新文档,特别是用户下的联系人 - Create new document in .nsf file using interop.domino.dll c# specially a contact under user 使用C#从NSF文件中读取Lotus Notes文档和项目 - Read Lotus Notes documents and items from NSF file with C# 如何在C#中播放nsf音乐? (制作游戏) - How do I play nsf music in C#? (making a game) 检查NSF文件是否受密码保护,是否使用C#。建议某些dll在未安装Domino服务器的情况下访问NSF文件 - Check whether NSF File is Password Protected or Not using C#.Suggest some dll to access NSF file without Domino Server installed 如何在C#中使用iTextSharp编辑PDF文件中的命名目标? - How to edit named destination in PDF file using iTextSharp with C#? 如何使用c#轻松编辑excel文件中的单元格值 - How to easily edit cell value in excel file using c# 如何使用C#编辑文本文件? - How can I edit a text file using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM