title: Get current opened document
body: <p>I'm trying to figure out how to get the currently opened document on Lotus Notes through C#, but I cannot. Even though I researched half a day on Google, I couldn't find anything useful.</p>
  
  <p>With my code I get the view I want, the database I want, etc, but I just would like to get the opened document. I tried something like IsUIDocOpen, but none of the full collection contains it as true.</p>
  
  <p>Does someone know if there is any different between an opened document and a non-opened document trough Domino API? My workaround is to get the subject of the email and the size of the email and compare each one and when it matches get the Entry ID and then get the information I need - but that takes too long, especially when the inbox is big.</p>
  
  <p>Any suggestions?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>NotesSession session = new NotesSession();
  
  session.Initialize(sPassword);
  notedb = session.GetDatabase(server, filename, false);
  if (notedb.IsOpen)
  {
    mailView = notedb.GetView("$Inbox");
  
    mailDoc = mailView.GetLastDocument();
    //mailDoc = mailView.GetDocumentByKey();
    try
    {
      while (mailDoc != null)
      {
        NotesItem item = mailDoc.GetFirstItem("From");
  
        if (item != null)
        {
          MessageBox.Show("From = " + item.Text);
        }
      }
    }
  }
  </code></pre>
  
  <p>Solution: should be something like:  <code>mailDoc = mailView.GetCurrentDocument();</code> // But obviously this method does not exist :D</p>
  
  <p>=====================================================================================
  Solution code:</p>
  
  <pre><code>Type NotesUIWorkspaceType = Type.GetTypeFromProgID("Notes.NotesUIWorkspace", true);
  object workspace = Activator.CreateInstance(NotesUIWorkspaceType);
  object uiDoc = NotesUIWorkspaceType.InvokeMember("CurrentDocument", BindingFlags.GetProperty, null, workspace, null);
  Type NotesUIDocument = uiDoc.GetType();
  object Subject = NotesUIDocument.InvokeMember("FieldGetText", BindingFlags.InvokeMethod, null, uiDoc, new Object[] { "Subject" });
  string subject = "test";
  
  NotesUIDocument.InvokeMember("FieldSetText", BindingFlags.InvokeMethod, null, uiDoc, new Object[] { "Subject", subject });
  object Body = NotesUIDocument.InvokeMember("FieldGetText", BindingFlags.InvokeMethod, null, uiDoc, new Object[] { "Body" });
  </code></pre>