/// <summary> /// AUTHOR: Ashok Kolwal /// COMPANY: VITRANA /// Version: 1.0 /// Description: The execute method of an IDfMoveOperation object moves the current versions of documents or folders from one /// repository location to an other by unlinking them from the source location and linking them to the destination. /// Versions other than the current version remain linked to the original location. /// Last Modified date: 11 Jul,2017 /// </summary> /// <param name="mySession"></param> /// <param name="docId"></param> /// <param name="destination"></param> /// <returns></returns> public String MoveObject(IDfSession mySession, String docId, String destination) { try { IDfId idObj = mySession.getIdByQualification("dm_sysobject where r_object_id='" + docId + "'"); // Create a new client instance. IDfClientX clientx = new DfClientX(); // Use the factory method to create an IDfCopyOperation instance. IDfMoveOperation mo = clientx.getMoveOperation(); // Create an instance for the destination directory. IDfFolder destinationDirectory = mySession.getFolderByPath(destination); // Set the destination directory by ID. mo.setDestinationFolderId(destinationDirectory.getObjectId()); // Create a document object that represents the document being copied. IDfDocument doc = (IDfDocument)mySession.getObject(idObj); // Create a move node, adding the document to the move operation object. IDfMoveNode node = (IDfMoveNode)mo.add(doc); // Execute and return results if (mo.execute()) { return("Move operation successful."); } else { return("Move operation failed."); } } catch (Exception ex) { Console.WriteLine("Error while moving object : " + ex.Message + "\n StackTrace: " + ex.StackTrace); return(null); } }
/// <summary> /// AUTHOR: Ashok Kolwal /// COMPANY: VITRANA /// Version: 1.0 /// Description: Creating a folder is similar to creating a cabinet. The essential differences are that you will /// create a dm_folder object and identify the parent cabinet or folder in which you’llcreate it /// Last Modified date: 11 Jul,2017 /// </summary> /// <param name="sessionManager"></param> /// <param name="repositoryName"></param> /// <param name="folderName"></param> /// <param name="parentName"></param> /// <returns></returns> public Boolean MakeFolder(IDfSessionManager sessionManager, String repositoryName, String folderName, String parentName) { IDfSession mySession = null; try { mySession = sessionManager.getSession(repositoryName); IDfSysObject newFolder = (IDfFolder)mySession.newObject(DM_FOLDER); IDfFolder aFolder = mySession.getFolderByPath(parentName + "/" + folderName); if (aFolder == null) { newFolder.setObjectName(folderName); newFolder.link(parentName); newFolder.save(); return(true); } else { return(false); } } catch (Exception ex) { Console.WriteLine("Error while creating Folder: " + ex.Message + "\n StackTrace: " + ex.StackTrace); return(false); } finally { sessionManager.release(mySession); } }
/// <summary> /// AUTHOR: Ashok Kolwal /// COMPANY: VITRANA /// Version: 1.0 /// Description: A cabinet is a top level container object used to hold folders. /// The cabinet is, in fact, a type of folder, and is created using the interface IDfFolder. /// Setting its object type to“dm_cabinet”gives it additional features, including the ability to exist as a top-level object. /// Last Modified date: 11 Jul,2017 /// </summary> /// <param name="sessionManager"></param> /// <param name="repositoryName"></param> /// <param name="cabinetName"></param> /// <returns></returns> public Boolean MakeCabinet(IDfSessionManager sessionManager, String repositoryName, String cabinetName) { IDfSession mySession = null; try { mySession = sessionManager.getSession(repositoryName); // check to see if the cabinet already exists IDfFolder myCabinet = mySession.getFolderByPath("/" + cabinetName); if (myCabinet == null) { IDfSysObject newCabinet = (IDfFolder)mySession.newObject(DM_CABINET); newCabinet.setObjectName(cabinetName); newCabinet.save(); return(true); } else { return(false); } } catch (Exception ex) { Console.WriteLine("Error while creating cabinet: " + ex.Message + "\n StackTrace: " + ex.StackTrace); return(false); } finally { sessionManager.release(mySession); } }
/// <summary> /// AUTHOR: Ashok Kolwal /// COMPANY: VITRANA /// Version: 1.0 /// Description: The execute method of an IDfCopyOperation object copies the current versions of documents /// or folders from one repository location to another. /// Last Modified date: 11 Jul,2017 /// </summary> /// <param name="sessionManager"></param> /// <param name="repositoryName"></param> /// <param name="docId"></param> /// <param name="destination"></param> /// <returns></returns> public String CopyDocument(IDfSessionManager sessionManager, String repositoryName, String docId, String destination) { IDfSession mySession = null; StringBuilder sb = new StringBuilder(""); try { mySession = sessionManager.getSession(repositoryName); // Get the object ID based on the object ID string. IDfId idObj = mySession.getIdByQualification("dm_sysobject where r_object_id='" + docId + "'"); // Instantiate an object from the ID. IDfSysObject sysObj = (IDfSysObject)mySession.getObject(idObj); // Create a new client instance. IDfClientX clientx = new DfClientX(); // Use the factory method to create an IDfCopyOperation instance. IDfCopyOperation co = clientx.getCopyOperation(); // Remove the path separator if it exists. if (destination.LastIndexOf("/") == destination.Length - 1 || destination.LastIndexOf("\\") == destination.Length - 1) { destination = destination.Substring(0, destination.Length - 1); } // Create an instance for the destination directory. IDfFolder destinationDirectory = mySession.getFolderByPath(destination); // Set the destination directory by ID. co.setDestinationFolderId(destinationDirectory.getObjectId()); // Create a document object that represents the document being copied. //IDfDocument doc = (IDfDocument)mySession.getObject(new DfId(docId)); IDfDocument doc = (IDfDocument)mySession.getObject(idObj); // Create a copy node, adding the document to the copy operation object. IDfCopyNode node = (IDfCopyNode)co.add(doc); // Execute and return results if (co.execute()) { return("Copy operation successful."); } else { return("Copy operation failed."); } } // Handle any exceptions. catch (Exception ex) { Console.WriteLine("Error while copying object : " + ex.Message + "\n StackTrace: " + ex.StackTrace); return("Exception has been thrown: " + ex); } // Always, always, release the session in the "finally" clause. finally { sessionManager.release(mySession); } }