Error IManExt ImportCmd

I am writing a small application using C # to copy a document to the My Documents folder of individuals on our DMS server.

I added the code in the list provided in "WorkSite SDK 8: Using the IMANEXT2Lib.IManRefileCmd File to Create New Documents Files".

Using this code in a WinForm application, I have no problem copying a file from the source folder to the users ’My Documents DMS folder.

However, if I use the code in the command line application /.dll or any other type of application (except WinForm) during the copying process, I get error messages;

1.

Error trying to register an event!

IManExt: an error occurred while trying to register the event!

Access is denied.

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

            }


        }

    }

>

+3
1

- .

, - .

, winform # "ApartmentState" ([STAThread]).

.NET .

: [STAThread] Main.

, IMANxxx.dll, ApartmentState, .

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

"ApartmentState" , .

+2

Source: https://habr.com/ru/post/1725971/


All Articles