English 中文(简体)
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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签