IManExt ImportCmd麻烦

时间:2009-12-17 16:42:07

标签: c# logging dms autonomy imanage

我一直在使用C#编写一个小应用程序,将文档复制到DMS服务器上的个人“我的文档”文件夹中。

我已经在“WorkSite SDK 8:利用IMANEXT2Lib.IManRefileCmd到文件新文档文件夹”博客中提供的列表周围添加了代码。

在WinForm应用程序中使用此代码我可以将文件从源文件夹复制到用户DMS“我的文档”文件夹中。

但是,如果我在复制过程中使用命令行application / .dll中的代码或任何其他类型的应用程序(WinForm除外),我会收到错误消息;

1

  

尝试记录事件时发生错误!

     

IManExt:尝试记录事件时发生错误!

     

访问被拒绝。

2

  

文档已导入数据库,但无法添加到   文件夹。

     

IManExt:文档已导入数据库,但无法导入   添加到文件夹。

     

IManExt.LogRuleEventsCmd.1:尝试记录事件时发生错误!

     

IManExt.LogRuleEventsCmd.1:访问被拒绝。

尝试记录事件时发生错误!

- % -

有没有人知道为什么我在使用非WinForms应用程序复制文档时收到“拒绝访问”错误消息? 我需要做些什么来解决这个问题?

任何帮助都会很棒!

代码到位:

    public void moveToDMS(String servName, String dBName, String foldName)
    {
        const string SERVERNAME = servName; //Server name
        const string DATABASENAME = dBName; //Database name
        const string FOLDERNAME = foldName; //Matter alias of workspace

        IManDMS dms = new ManDMSClass();
        IManSession sess = dms.Sessions.Add(SERVERNAME);
        sess.TrustedLogin();

        //Get destination database.
        IManDatabase db = sess.Databases.ItemByName(DATABASENAME);

        //Get destination folder by folder and owner name.
        IManFolderSearchParameters fparms = dms.CreateFolderSearchParameters();
        fparms.Add(imFolderAttributeID.imFolderOwner, sess.UserID);
        fparms.Add(imFolderAttributeID.imFolderName, FOLDERNAME);           

        //Build a database list in which to search.
        ManStrings dblist = new ManStringsClass();
        dblist.Add(db.Name);

        IManFolders results = sess.WorkArea.SearchFolders(dblist, fparms);

        if (results.Empty == true)
        {
            //No results returned based on the search criteria.
            Console.WriteLine("NO RESULTS FOUND!");
        }

        IManDocumentFolder fldr = null;

        if (results.Empty == false)
        {
            //Assuming there is only one workspace returned from the results.
            fldr = (IManDocumentFolder)results.ItemByIndex(1);
        }

        if (fldr != null)
        {
            // Import file path
            string docPath = @"C:\Temp\";
            string docName = "MyWord.doc";

            // Create an instance of the ContextItems Collection Object.
            ContextItems context = new ContextItemsClass();

            // Invoke ImportCmd to import a new document to WorkSite database.
            ImportCmd impCmd = new ImportCmdClass();

            // The WorkSite object you pass in can be a database, session, or folder.
            // Depends on in where you want the imported doc to be stored.
            context.Add("IManDestinationObject", fldr); //The destination folder.

            // Filename set here is used for easy example, a string variable is normally used here
            context.Add("IManExt.Import.FileName", docPath + docName);

            // Document Author
            context.Add("IManExt.Import.DocAuthor", sess.UserID); //Example of a application type.

            // Document Class
            context.Add("IManExt.Import.DocClass", "BLANK"); //Example of a document class.
            //context.Add("IManExt.Import.DocClass", "DOC"); //Example of a document class.

            // Document Description (optional)
            context.Add("IManExt.Import.DocDescription", docName); //Using file path as example of a description.

            // Skip UI
            context.Add("IManExt.NewProfile.ProfileNoUI", true);

            impCmd.Initialize(context);
            impCmd.Update();

            if (impCmd.Status == (int)CommandStatus.nrActiveCommand)
            {
                impCmd.Execute();

                bool brefresh = (bool)context.Item("IManExt.Refresh");
                if (brefresh == true)
                {
                    //Succeeded in importing a document to WorkSite
                    IManDocument doc = (IManDocument)context.Item("ImportedDocument");

                    //Succeeded in filing the new folder under the folder.
                    Console.WriteLine("New document number, " + doc.Number + ", is successfully filed to " + fldr.Name + " folder.");
                }

            }


        }

    }

public void moveToDMS(String servName, String dBName, String foldName) { const string SERVERNAME = servName; //Server name const string DATABASENAME = dBName; //Database name const string FOLDERNAME = foldName; //Matter alias of workspace IManDMS dms = new ManDMSClass(); IManSession sess = dms.Sessions.Add(SERVERNAME); sess.TrustedLogin(); //Get destination database. IManDatabase db = sess.Databases.ItemByName(DATABASENAME); //Get destination folder by folder and owner name. IManFolderSearchParameters fparms = dms.CreateFolderSearchParameters(); fparms.Add(imFolderAttributeID.imFolderOwner, sess.UserID); fparms.Add(imFolderAttributeID.imFolderName, FOLDERNAME); //Build a database list in which to search. ManStrings dblist = new ManStringsClass(); dblist.Add(db.Name); IManFolders results = sess.WorkArea.SearchFolders(dblist, fparms); if (results.Empty == true) { //No results returned based on the search criteria. Console.WriteLine("NO RESULTS FOUND!"); } IManDocumentFolder fldr = null; if (results.Empty == false) { //Assuming there is only one workspace returned from the results. fldr = (IManDocumentFolder)results.ItemByIndex(1); } if (fldr != null) { // Import file path string docPath = @"C:\Temp\"; string docName = "MyWord.doc"; // Create an instance of the ContextItems Collection Object. ContextItems context = new ContextItemsClass(); // Invoke ImportCmd to import a new document to WorkSite database. ImportCmd impCmd = new ImportCmdClass(); // The WorkSite object you pass in can be a database, session, or folder. // Depends on in where you want the imported doc to be stored. context.Add("IManDestinationObject", fldr); //The destination folder. // Filename set here is used for easy example, a string variable is normally used here context.Add("IManExt.Import.FileName", docPath + docName); // Document Author context.Add("IManExt.Import.DocAuthor", sess.UserID); //Example of a application type. // Document Class context.Add("IManExt.Import.DocClass", "BLANK"); //Example of a document class. //context.Add("IManExt.Import.DocClass", "DOC"); //Example of a document class. // Document Description (optional) context.Add("IManExt.Import.DocDescription", docName); //Using file path as example of a description. // Skip UI context.Add("IManExt.NewProfile.ProfileNoUI", true); impCmd.Initialize(context); impCmd.Update(); if (impCmd.Status == (int)CommandStatus.nrActiveCommand) { impCmd.Execute(); bool brefresh = (bool)context.Item("IManExt.Refresh"); if (brefresh == true) { //Succeeded in importing a document to WorkSite IManDocument doc = (IManDocument)context.Item("ImportedDocument"); //Succeeded in filing the new folder under the folder. Console.WriteLine("New document number, " + doc.Number + ", is successfully filed to " + fldr.Name + " folder."); } } } }

1 个答案:

答案 0 :(得分:2)

以防这有助于其他人。

似乎我的问题是线程问题的结果。

我注意到我创建的C#winform应用程序自动设置为在单个“ApartmentState”主题([STAThread])上运行。

而控制台应用程序&类库线程状态和管理尚未在项目中定义,并且正在使用默认的.NET配置进行处理。

要使其正常工作:在控制台应用程序中,我刚在主方法调用上方的行上添加了[STAThread]标记。

在类库中,我为引用IMANxxx.dll的函数定义了一个线程,并设置了ApartmentState,例如。

Thread t = new Thread(new ThreadStart(PerformSearchAndMove));
t.SetApartmentState(ApartmentState.STA);
t.Start();

在确保单个“ApartmentState”线程实施的两种情况下,set都可以解决问题。