/// <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: A document object represents both the content of a document and the metadata that describe the document. /// In most cases, you create a document by importing an existing document from a local source to the repository /// Last Modified date: 11 Jul,2017 /// </summary> /// <param name="sessionManager">The session manager object</param> /// <param name="repositoryName">The repository name </param> /// <param name="documentName">The document name of document which will visible on documentum server</param> /// <param name="documentType">Document extension</param> /// <param name="sourcePath">Input file local machine path e.g D:\test1.txt</param> /// <param name="folderName">/CabinetName/FolderName e.g /dmadmin/TransformPV</param> /// <returns>IDFId</returns> public List <UploadDocumentEntity> MakeDocument(IDfSessionManager sessionManager, String repositoryName, String folderPath, String documentInputFolderPath) { List <UploadDocumentEntity> docList = new List <UploadDocumentEntity>(); try { // Upload files form local drive folder. if (Directory.Exists(documentInputFolderPath)) { string[] documentList = Directory.GetFiles(documentInputFolderPath); if (documentList != null && documentList.Length > 0) { IDfSession mySession = sessionManager.getSession(repositoryName); // Console.WriteLine("[MakeDocument] IDfSession instance is created"); try { string idfID = null; string documentFullName = null; string documentName = null; string docExtension = null; string documentType = null; for (int i = 0; i < documentList.Length; i++) { try { // Get file individual file for Input document directory. documentFullName = documentList[i]; documentName = Path.GetFileNameWithoutExtension(documentFullName); docExtension = Path.GetExtension(documentFullName); documentType = GetFileMetaData(documentFullName)[0]; FileInfo fileInfo = new FileInfo(documentFullName); IDfSysObject newDoc = (IDfSysObject)mySession.newObject(DM_DOCUMENT); newDoc.setObjectName(documentName); newDoc.setContentType(documentType); newDoc.setFile(documentFullName); //-- /CabinetName/FolderName newDoc.link(folderPath); newDoc.save(); idfID = newDoc.getObjectId().getId(); //////////////////////////////////////////////// // IDfApplyExecSQL execSQL = DfAdminCommand.getCommand(__Fields.APPLY_EXEC_SQL); // IDfApplyExecSQL execSQL =(IDfApplyExecSQL) DfAdminCommand.getCommand(109); // execSQL.setQuery("DM_DOCUMENT where r_object_id='"+idfID+"'"); // IDfCollection sqlResult= execSQL.execute(mySession); // Type t= sqlResult.GetType(); /////////////////////////////////////////////////// // Set out param value. UploadDocumentEntity uploadDocObj = new UploadDocumentEntity(); uploadDocObj.IdfID = idfID; uploadDocObj.IdfPath = newDoc.getPath(0); uploadDocObj.DocumentName = string.Concat(documentName, docExtension); uploadDocObj.Status = 1; uploadDocObj.ExceptionMessage = null; docList.Add(uploadDocObj); } catch (Exception ex) { UploadDocumentEntity uploadDocObj = new UploadDocumentEntity(); uploadDocObj.IdfID = idfID; uploadDocObj.DocumentName = string.Concat(documentName, docExtension); uploadDocObj.Status = 0; uploadDocObj.ExceptionMessage = ServiceBase.GetExceptionMessage(ex); docList.Add(uploadDocObj); } } } catch (Exception ex) { throw new Exception("[MakeDocument] Error while get sessionManager.getSession() :" + ex.Message, ex); } finally { sessionManager.release(mySession); } } else { throw new Exception("[MakeDocument] InputDocumentPath folder does not have files for upload in documentum"); } } else { throw new Exception("[MakeDocument] InputDocumentPath does not exists..."); } } catch (Exception ex) { throw new Exception("[MakeDocument] GeneralException: " + ex.Message); } return(docList); }