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

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);
            }

        }
    }
}

你可能感兴趣的:(.net,C#,domino,拆离附件)