2014年2月11日 星期二

C#使用OLE來操作Lotus Notes 的 UI

1.加入lotus的參考(當然要先裝Lotus Notes Client)


2.Source Code Sample

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using lotus;
using System.Reflection;


namespace NotesOle
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Type NotesSession = Type.GetTypeFromProgID("Notes.NotesSession");
            Type NotesUIWorkspace = Type.GetTypeFromProgID("Notes.NotesUIWorkspace");
            Object sess = Activator.CreateInstance(NotesSession);
            Object ws = Activator.CreateInstance(NotesUIWorkspace);

            NotesUIWorkspace.InvokeMember("OpenDatabase", BindingFlags.InvokeMethod, null, ws, new Object[] { "NotesSrv3/Adimmune", "Record\\AgnSchedule.nsf", "MailView" });
            Object uidb = NotesUIWorkspace.InvokeMember("GetCurrentDatabase", BindingFlags.InvokeMethod, null, ws, null);

            Object db = NotesUIWorkspace.InvokeMember("Database", BindingFlags.GetProperty, null, uidb, null);
            Type NotesDatabase = db.GetType();

            Type NotesView = Type.GetTypeFromProgID("Notes.NotesView");
            Object view = NotesUIWorkspace.InvokeMember("GetView", BindingFlags.InvokeMethod, null, db, new Object[] { "MailView" });

            Object Document = NotesUIWorkspace.InvokeMember("GetFirstDocument", BindingFlags.InvokeMethod, null, view, new Object[] { });
            Object DocumentUI = NotesUIWorkspace.InvokeMember("EditDocument", BindingFlags.InvokeMethod, null, ws, new Object[] { true, Document });

            //Object uidoc = NotesUIWorkspace.InvokeMember("ComposeDocument", BindingFlags.InvokeMethod, null, ws, new Object[] { "NotesSrv3/Adimmune", "Record\\AgnSchedule.nsf", "Memo", 0, 0, true });
            //Type NotesUIDocument = uidoc.GetType();
            Type NotesUIDocument2 = Document.GetType();

            //NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "EnterSendTo", "Test sendto" });
            //NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Subject", "Test subject" });
            //NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Body", "Test body" });

            // bring the Notes window to the front
            //String windowTitle = (String)NotesUIDocument.InvokeMember("WindowTitle", BindingFlags.GetProperty, null, uidoc, null);
            String[] TestString= (String[])NotesUIDocument2.InvokeMember("SendTO", BindingFlags.GetProperty, null, Document, null);

        }
    }
}