public Form1() { InitializeComponent(); serviceFactory = ServiceFactory.Instance; } private void Form1_Load(object sender, EventArgs e) { objectService = serviceFactory.GetRemoteService<IObjectService>( GetServiceContext(repository, userName, password, domain), serviceModule, contextRoot); } private void btnCreateFolder_Click(object sender, EventArgs e) { CreateCabinet(folderPath, repository); } private void btnUpLoadFile_Click(object sender, EventArgs e) { openFileDialog.Filter = "all File|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string objectName = Path.GetFileName(openFileDialog.FileName); objectName = objectName.Substring(0, objectName.IndexOf('.')); string typeObject = Path.GetExtension(openFileDialog.FileName); typeObject = typeObject.Substring(1); the problem is here!!! if typeObject is "txt" the program fails as it should be "text" or "crtext" not to fail, how can I get those values BuildObject(repository, typeObjectIdentity, objectName, subject, title, keywords, typeObject, openFileDialog.FileName); MessageBox.Show("Listo...!"); } } private void CreateCabinet(string folderPath, string repositoryName) { try { objectService.CreatePath(new ObjectPath(folderPath), repositoryName); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void BuildObject(string repositoryName, string typeObjectIdentity, string objectName, string subject, string title, string[] keywords, string typeObject, string contentPath) { DataPackage dataPackage = new DataPackage(); try { ReferenceRelationship referenceRelationship = setReferenceRelationship(folderPath, repositoryName); Emc.Documentum.FS.DataModel.Core.DataObject dataObject = new Emc.Documentum.FS.DataModel.Core.DataObject(new ObjectIdentity(repositoryName), typeObjectIdentity); dataObject.Properties.Set("object_name", objectName); dataObject.Properties.Set("subject", subject); dataObject.Properties.Set("title", title); dataObject.Properties.Set("keywords", keywords); dataObject.Properties.Set("a_content_type", typeObject); if (!File.Exists(contentPath)) MessageBox.Show("The file: " + contentPath + " does not exist"); dataObject.Contents.Add(new FileContent(contentPath, typeObject)); dataObject.Relationships.Add(referenceRelationship); dataPackage.AddDataObject(dataObject); OperationOptions operationOptions = null; objectService.Create(dataPackage, operationOptions); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private IServiceContext GetServiceContext(string repositoryName, string userName, string password, string domain) { IServiceContext serviceContext = ContextFactory.Instance.NewContext(); try { serviceContext.AddIdentity(new RepositoryIdentity(repositoryName, userName, password, domain)); ContentTransferProfile contentTransferProfile = new ContentTransferProfile(); contentTransferProfile.TransferMode = ContentTransferMode.MTOM; contentTransferProfile.Geolocation = "Pleasanton"; serviceContext.SetProfile(contentTransferProfile); } catch (Exception ex) { MessageBox.Show(ex.Message); } return serviceContext; } private ReferenceRelationship setReferenceRelationship(string folderPath, string repository) { ReferenceRelationship referenceRelationship = new ReferenceRelationship(); try { ObjectIdentity objectIdentity = new ObjectIdentity(new ObjectPath(folderPath), repository); referenceRelationship.Name = Relationship.RELATIONSHIP_FOLDER; referenceRelationship.Target = objectIdentity; referenceRelationship.TargetRole = Relationship.ROLE_PARENT; } catch (Exception ex) { MessageBox.Show(ex.Message); } return referenceRelationship; } |