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

发布于 2024-08-10 07:44:53 字数 879 浏览 9 评论 0原文

我想以编程方式更改 NSF 项目的一些值,然后保存它。(即编辑 NSF 文件,然后保存版本)

例如:

我想将所有邮件的发件人名称设置为“[电子邮件受保护]"。(使用 Domino.dll)。

我尝试过的解决方案:(交换“To”和“From”值)

String Temp_From = ((object[])docInbox.GetItemValue("From"))[0] as String; String Temp_SendTo = ((object[])docInbox.GetItemValue("SendTo"))[0] as String; docInbox.ReplaceItemValue("From", Temp_SendTo); docInbox.ReplaceItemValue("SendTo", Temp_From); docInbox.Save(真,假,假);

/* 也适用于以下字段:

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

对于收件人:displaySendTo,EnterSendTo,Envelope_to,tmpDisplaySendTo

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

在上面的代码中,成功编辑后的更改值不会反映在 Nsf 文件中。 但是当我以编程方式读取编辑的 Nsf(在不同位置复制修改的文件)文件时,它显示更改的值。(为什么此处看不到更改?)

I want to programaticaly change some values to NSF item and then want to save it.(i.e to edit NSF File and then save the editions)

for example:

I want to set Sender name of all mails to "[email protected]".(Using Domino.dll).

Solution I tried: (Swaping of To and From values)

String Temp_From = ((object[])docInbox.GetItemValue("From"))[0] as String;
String Temp_SendTo = ((object[])docInbox.GetItemValue("SendTo"))[0] as String;
docInbox.ReplaceItemValue("From", Temp_SendTo);
docInbox.ReplaceItemValue("SendTo", Temp_From);
docInbox.Save(true, false, false);

/* Applied for following fields also:

For From: AltFrom,DisplayFrom,DisplayFrom_2,dspFrom,ForwardedFrom,INetFrom,tmpDisplayFrom

For To : displaySendTo,EnterSendTo,Envelope_to,tmpDisplaySendTo

Also Tried for saving : docInbox.Save(true, true, true); */

In above code after successful editing changes values are not reflected in Nsf File.
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 ?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

停顿的约定 2024-08-17 07:44:53

“编程指南,第 2 卷:LotusScript/COM/OLE 类”可以在此处找到:
http://www-12.lotus.com/ldd /doc/uafiles.nsf/docs/DESIGNER70/

作为简要总结,一旦您有了文档的句柄,您就可以使用 Items 迭代该文档上的所有现有字段(“项目”)财产;您可以使用 ReplaceItemValue 和/或 AppendItemValue 方法更新该文档上的给定字段。

The "Programming Guide, Volume 2: LotusScript/COM/OLE Classes" can be found here:
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; and you can update a given field on that document using the ReplaceItemValue and/or AppendItemValue methods.

黯然 2024-08-17 07:44:53

您正在使用 Notes 客户端检查结果吗?我想这种行为可以用客户端相当激进的缓存来解释。在检查程序结果之前,请尝试从数据目录中删除文件 cache.ndk

此外,Notes“项目”通常包含一个值数组 - 例如,如果一封邮件已发送到多个地址,则交换 SendToFrom 字段的方法将丢失数据。人们。尝试复制整个object[]

Are you checking the result with the Notes client? 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.

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. Try copying the entire object[] instead.

丶视觉 2024-08-17 07:44:53

我就这么做过一次。

您必须向项目添加新引用,并在“添加引用”对话框中选择“COM”。在列表中找到名为“Lotus Domino Objects”的组件并添加它。您将看到一个名为“Domino”的新引用添加到您的项目中。该 COM 组件由 Lotus Notes 客户端安装。您的开发计算机中必须有它,并且在运行应用程序时也必须安装它。

从那时起,您可以使用在 NotesDesigner 中使用 Lotusscript 进行开发时可用的大部分类。

添加适当的“using”语句:

using Domino;

创建笔记会话:

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.

获取数据库:

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

获取一些文档,例如: 今天的约会(如果您打开的数据库是您的 mail.nsf)

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

迭代您的集合:

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

我注意到此界面的一个问题:没有 session.Close() 方法或类似的方法,并且一旦 GC 收集 C# 对象,我的会话就不会在服务器中关闭。一旦我打开一个新的 NotesSession(),只要我的 c# 线程还活着,它就在 domino 服务器中保持活动状态。为了解决这个问题,我必须创建后台线程,并且仅从线程内实例化新的 NotesSession() 对象。线程在启动之前还必须使用 STA 公寓模式进行设置。

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

我不确定这个问题是否真的是界面中的问题,或者是我在代码中做错的其他问题。但如果有人面临这个问题:线程是我解决它的方法。

I did that once.

You have to add a new reference to your project and choose 'COM' in the 'Add Reference' dialog. Find the component named 'Lotus Domino Objects' in the list and add it. You will see a new reference called 'Domino' added to your project. That COM component is installed by the Lotus Notes Client. 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.

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)

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. Once I opened a new NotesSession(), it stayed alive in the domino server as long as my c# thread was alive. To solve that problem, I had to create background threads and only instantiate new NotesSession() objects from within the threads. The threads also had to be setup with STA apartment mode before being started.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文