AnsweredAssumed Answered

Trying to Bulk Unlock from standalone c# application

Question asked by Sean Donnelly on Apr 11, 2017
Latest reply on Apr 11, 2017 by Peter Brinkhuis

Hello,

I am trying to check in (or unlock) all files for the logged in user via standalone c# application button. See my code below. It seems to be breaking at the point of the batchUnlocker. Any idea why?

 

        private void buttonCheckInFiles_Click(object sender, EventArgs e)

        {

            IEdmVault7 vault2 = null;

            if (vault1 == null)

            {

                vault1 = new EdmVault5();

            }

            vault2 = (IEdmVault7)vault1;

 

 

            if (!vault1.IsLoggedIn)

            {

                vault1.LoginAuto("Test Vault for FETasks", this.Handle.ToInt32());

            }

 

 

            IEdmBatchUnlock2 batchUnlocker;

            IEdmSelectionList6 fileList = null;

            EdmSelectionObject poSel;

            EdmSelItem[] ppoSelection = new EdmSelItem[11];

            int fileCount = 0;

            IEdmFile5 aFile;

            IEdmFolder5 aFolder;

            IEdmFolder5 ppoRetParentFolder;

            IEdmPos5 aPos;

            string str;

 

 

            bool retVal;

 

 

            //Declare an IEdmUserMgr5 object

            IEdmUserMgr5 userMgr = default(IEdmUserMgr5);

 

 

            //The IEdmUserMgr5 interface is implemented by the

            //same class as the IEdmVault5 interface,

            //so you can assign the value of

            //the IEdmVault5 object

            userMgr = (IEdmUserMgr5)vault2;

 

 

            IEdmUser5 user = default(IEdmUser5);

            user = userMgr.GetLoggedInUser();

 

 

            MessageBox.Show(user.Name);

 

               //Breaking right here

            batchUnlocker = (IEdmBatchUnlock2)vault2.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);

 

 

            //Search for all text files in the vault

            IEdmSearch5 Search = default(IEdmSearch5);

            Search = (IEdmSearch5)vault2.CreateUtility(EdmUtility.EdmUtil_Search);

 

 

            Search.FindLockedFiles = true;

            Search.FindUnlockedFiles = false;

 

 

            IEdmSearchResult5 Result = default(IEdmSearchResult5);

            Result = Search.GetFirstResult();

 

 

            int i = 0;

            while (Result != null)

            {

                if (Result.LockedByUserName == user.Name)

                {

                    aFile = vault2.GetFileFromPath(Result.Path, out ppoRetParentFolder);

                    MessageBox.Show(aFile.Name);

                    aPos = aFile.GetFirstFolderPosition();

                    aFolder = aFile.GetNextFolder(aPos);

                    ppoSelection[i] = new EdmSelItem();

                    ppoSelection[i].mlDocID = aFile.ID;

                    ppoSelection[i].mlProjID = aFolder.ID;

                }

                Result = Search.GetNextResult();

                i++;

            }

 

 

            batchUnlocker.AddSelection((EdmVault5)vault2, ref ppoSelection);

 

 

            if ((batchUnlocker != null))

            {

                batchUnlocker.CreateTree(this.Handle.ToInt32(), (int)EdmUnlockBuildTreeFlags.Eubtf_ShowCloseAfterCheckinOption + (int)EdmUnlockBuildTreeFlags.Eubtf_MayUnlock);

 

 

                batchUnlocker.Comment = "Updates";

                fileList = (IEdmSelectionList6)batchUnlocker.GetFileList((int)EdmUnlockFileListFlag.Euflf_GetUnlocked + (int)EdmUnlockFileListFlag.Euflf_GetUndoLocked + (int)EdmUnlockFileListFlag.Euflf_GetUnprocessed);

 

 

                aPos = fileList.GetHeadPosition();

 

 

                str = "Getting " + fileCount + " files: ";

                while (!(aPos.IsNull))

                {

                    fileList.GetNext2(aPos, out poSel);

                    str = str + Constants.vbLf + poSel.mbsPath;

                }

 

 

                //MsgBox(str)

 

 

                retVal = batchUnlocker.ShowDlg(this.Handle.ToInt32());

 

 

                object statuses = null;

                if ((retVal))

                {

                    batchUnlocker.UnlockFiles(this.Handle.ToInt32(), null);

                    statuses = batchUnlocker.GetStatus((int)EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag);

                    Interaction.MsgBox("Close Files after Check In selected? " + statuses);

                }

 

 

            }

Outcomes