开发者

How to Edit NSF file using c#?

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 "preeti@abc.com".(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 ?)


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜