Lotus Notes RichText - JackHu88/Comm GitHub Wiki

利用 LotusScript 灵活操作 Lotus Notes 富文本域

http://www.cnblogs.com/hannover/archive/2010/09/25/1834287.html https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_NOTESCOLOROBJECT_CLASS.html

Access (Domino) server with form based authentication

https://stackoverflow.com/questions/8731857/net-consuming-http-services-on-domino-server-with-form-based-authentication http://ziuek.blogspot.hk/2009/01/how-to-call-secured-domino-webservice.html

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Xml.Linq;

namespace WebDomino
{

    /// <summary>
    /// A stateful (authenticated) session with a Domino server.  Current version only supports
    /// forms based authentication, and does not permit bypassing authentication.
    /// </summary>
    public class DominoHttpSession
    {
        /// <summary>
        /// Username with which to authenticate to the Domino server, must be a legal web user name.
        /// </summary>
        public string UserName { set; get; }

        /// <summary>
        /// Web password of the authenticating account.
        /// </summary>
        public string Password { set; get; }

        /// <summary>
        /// The server on which the session will exist.  At this time, all connections must use
        /// the same server.  Untested but probably will work:  switching server name before establishing
        /// a connection, as long as the authentication cookies are shared.
        /// </summary>
        public string ServerHostName { set; get; }

        /// <summary>
        /// The session cookies.  Provided in case client code wants to analyze cookie content, but
        /// more likely only used internally to hold the authentication cookie from the server.
        /// </summary>
        public CookieContainer Cookies { get { return cookies; } }

        private CookieContainer cookies = new CookieContainer();

        /// <summary>
        /// Sends an HTTP GET to the server, expecting an XML response.   
        /// </summary>
        /// <param name="url">The full url to GET; proper syntax is the responsibility of the caller.</param>
        /// <returns>The XElement representing the returned XML text</returns>
        public XElement GetXml(string url)
        {
            return XElement.Parse(Get(url));
        }

        public string Get(string url)
        {
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.CookieContainer = cookies;
            request.ContentType = "text/html; charset=gb2312";
            request.Method = "GET";

            using (var responseStream = request.GetResponse().GetResponseStream())
            using (var reader = new StreamReader(responseStream, Encoding.GetEncoding("GB2312")))
            {
                var result = reader.ReadToEnd();
                return result;                
            }                                
        }

        /// <summary>
        /// Must be called to establish the session with the server.
        /// </summary>
        public void Authenticate()
        {            
            ServicePointManager.Expect100Continue = false;

            var request = (HttpWebRequest)WebRequest.Create(String.Format("http://{0}//names.nsf?Login", ServerHostName));
            /*request.CookieContainer = cookies;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            using (var requestStream = request.GetRequestStream())
            using (var writer = new StreamWriter(requestStream))
            {
                writer.Write("Username={0}&Password={1}", UserName,Password);
            }

            using (var responseStream = request.GetResponse().GetResponseStream())
            using (var reader = new StreamReader(responseStream))
            {
                var result = reader.ReadToEnd();  

                // Success is assumed here--in production code it should not be
            }*/
            request.Method = "POST";
                request.AllowAutoRedirect = false;
                request.ContentType = "application/x-www-form-urlencoded";
                request.CookieContainer = cookies;
                request.KeepAlive = false;
                request.ConnectionGroupName = Guid.NewGuid().ToString();

                // Prepare POST body
                string post = "Username=" + UserName + "&Password=" + Password;
                byte[] bytes = Encoding.ASCII.GetBytes(post);

                // Write data to request
                request.ContentLength = bytes.Length;
                Stream streamOut = request.GetRequestStream();
                streamOut.Write(bytes, 0, bytes.Length);
                streamOut.Close();
                // Get response

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 
                { 
                    if (response.StatusCode == HttpStatusCode.Found)
                    {
                       var result = reader.ReadToEnd();  
                       // Success is assumed here--in production code it should not be
                       Get(url);
                    }
               }                   
        }

        public ViewReader GetViewReader(string dbPath, string viewName)
        {
            return new ViewReader(this)
                   {
                       DbPath = dbPath,
                       View = viewName
                   };
        }

    }


}

C# 访问Domino对象,拆离富文本域中的附件

http://blog.csdn.net/kangkanglou/article/details/38776309

using System;  
using System.Collections.Generic;  
using System.Text;  
using Domino;  
using System.Configuration;  
using CommonFunctions;  
namespace NotesApplication  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            CommonFunctions.SystemLog logger;  
            string _DominoServer = System.Configuration.ConfigurationManager.AppSettings["NotesServer"];  
            string _DominoUser = System.Configuration.ConfigurationManager.AppSettings["NotesUserFile"];  
            string _DominoPass = System.Configuration.ConfigurationManager.AppSettings["NotesPassword"];  
            string localDBPath = System.Configuration.ConfigurationManager.AppSettings["LocalDB"];  
            string attPath = System.Configuration.ConfigurationManager.AppSettings["AttPath"];  
            string logPath = System.Configuration.ConfigurationManager.AppSettings["LogPath"];  
            string _DeleteSwitch = System.Configuration.ConfigurationManager.AppSettings["DeleteSwitch"];  
  
            logger = new SystemLog(logPath);  
  
            NotesSessionClass session;  
            session = new Domino.NotesSessionClass();  
            session.Initialize(_DominoPass);  
  
            NotesDatabase localDB;  
            NotesDatabase db;  
            NotesDocument doc;  
            NotesRichTextItem rtitem;  
            NotesView view;  
            NotesDocument newdoc;  
            NotesDocument tmpdoc;  
  
            logger.LogSystemMessage("_DominoServer: " + _DominoServer,true);  
            logger.LogSystemMessage("_DominoUser: " + _DominoUser,true);  
            logger.LogSystemMessage("_DominoPass: " + _DominoPass,true);  
            logger.LogSystemMessage("_AttPath:" +attPath,true);  
  
  
  
            try  
            {  
                db = session.GetDatabase(_DominoServer, _DominoUser, true);  
                if (db == null)  
                {  
                    logger.LogSystemMessage("db is null",true);  
                    return;  
                }  
  
                Console.WriteLine(db.Title);  
                logger.LogSystemMessage("db title " + db.Title,true);  
  
                localDB = session.GetDatabase("", localDBPath, false);  
  
                if (localDB == null)  
                {  
                    logger.LogSystemMessage("LocalDB is null",true);  
                    return;  
                }  
  
                Console.WriteLine(localDB.Title);  
                logger.LogSystemMessage("localDB title " + localDB.Title, true);  
  
                view = db.GetView("($Inbox)");  
  
                if (view == null)  
                {  
                    logger.LogSystemMessage("view is null",true);  
                    return;  
                }  
  
                Console.WriteLine(view.AllEntries.Count);  
                logger.LogSystemMessage("Server Inbox View = "+view.AllEntries.Count.ToString(),true);  
  
                doc = view.GetFirstDocument();  
                while (doc != null)  
                {  
                    tmpdoc = view.GetNextDocument(doc);  
                    newdoc = doc.CopyToDatabase(localDB);  
                    newdoc.PutInFolder("($Inbox)");  
                    if (_DeleteSwitch == "1")  
                    {  
                        doc.Remove(true);  
                    }  
                      
                    logger.LogSystemMessage(((object[])doc.GetItemValue("Subject"))[0].ToString(),true);  
                    doc = tmpdoc;  
                }  
  
                view = null;  
  
                view = localDB.GetView("($Inbox)");  
  
                if (view == null)  
                {  
                    return;  
                }  
  
                Console.WriteLine(view.AllEntries.Count);  
                logger.LogSystemMessage("Local Inbox View = "+view.AllEntries.Count.ToString(),true);  
  
                doc = view.GetFirstDocument();  
  
                while (doc != null)  
                {  
                    tmpdoc = view.GetNextDocument(doc);  
                    logger.LogSystemMessage("开始处理: " + ((object[])doc.GetItemValue("Subject"))[0].ToString(), true);  
                    if (doc.HasEmbedded)  
                    {  
                        logger.LogSystemMessage("包含附件,执行拆离操作!", true);  
  
                        rtitem = (NotesRichTextItem)doc.GetFirstItem("Body");  
  
                        Console.WriteLine(rtitem.type);  
  
                        if (rtitem.type == IT_TYPE.RICHTEXT)  
                        {  
                            Console.WriteLine(rtitem.EmbeddedObjects.ToString());  
  
                            Object[] att = (Object[])rtitem.EmbeddedObjects;  
  
                            for (int i = 0; i < att.Length; i++)  
                            {  
                                NotesEmbeddedObject o = (NotesEmbeddedObject)att[i];  
                                Console.WriteLine(o.type);  
  
                                if (o.type == EMBED_TYPE.EMBED_ATTACHMENT)  
                                {  
                                    o.ExtractFile("D:\\tmp\\" + o.Source);  
                                    logger.LogSystemMessage("D:\\tmp\\" + o.Source,true);  
                                }  
                            }  
  
                        }  
  
                          
                    }  
  
                    else  
                    {  
                        logger.LogSystemMessage("不包含附件,不做拆离操作!",true);  
                    }  
  
                    doc.RemoveFromFolder("($Inbox)");  
                    doc = tmpdoc;  
                }  
  
  
            }  
            catch (Exception e)  
            {  
                logger.LogSystemMessage(e.Message,true);  
                Console.WriteLine(e.Message);  
            }  
  
        }  
    }  
}  

Return an HTML representation of a Lotus Notes rich-text field

http://searchdomino.techtarget.com/tip/How-to-return-an-HTML-representation-of-a-Lotus-Notes-rich-text-field

string _DominoServer = System.Configuration.ConfigurationManager.AppSettings["NotesServer"];  //server/xxx/xx
string _DominoUser = System.Configuration.ConfigurationManager.AppSettings["NotesUserFile"];  //xxx\xxx.nsf
string _DominoPass = System.Configuration.ConfigurationManager.AppSettings["NotesPassword"];  //user password
NotesDatabase db;
NotesDocument doc;
NotesRichTextItem rtitem;
NotesView view;

try
{
    db = session.GetDatabase(_DominoServer, _DominoUser, true);
    view = db.GetView(@"Team Documents\By Date");
    doc = view.GetFirstDocument();

	NotesRichTextItem sourceField = (NotesRichTextItem)doc.GetFirstItem("Body");
    NotesDocument newND = db.CreateDocument();  
    newND.AppendItemValue("Form","MimeConvert");  
    NotesRichTextItem newRTItem = newND.CreateRichTextItem("RichTextField");
    newRTItem.AppendRTItem(sourceField);
    newND.Save( true,true,true);

    WebClient client = new WebClient();
    StringBuilder sb= new StringBuilder();
    // get the URL that will open that document
    using(Stream stream = client.OpenRead(newND.HttpURL))
    {
        // Get document as an HTMLstring as seen by the current domino server  
        using(StreamReader reader = new StreamReader(stream, Encoding.UTF8)) {
            while(reader.Peek() >= 0) {
                sb.Append(reader.ReadLine()); // or something...
            }
        }
    }
    String fullPage = sb.ToString();
    string[] separatingChars = { "</body>"};
    String[] passOne = fullPage.Split(new string[] { "</body>" }, System.StringSplitOptions.RemoveEmptyEntries);
    String[] arrBody = passOne[0].Split(new string[] { "<body text=\"#000000\" bgcolor=\"#FFFFFF\">" }, StringSplitOptions.RemoveEmptyEntries);
    String strBody = arrBody[1];
}


⚠️ **GitHub.com Fallback** ⚠️