【问题标题】:MFiles API setting propertyValueM 文件 API 设置属性值
【发布时间】:2017-09-16 06:57:59
【问题描述】:

我正在使用 MFiles API...

我想将 propertyDef 传递给 propertyValue...

此代码正在运行...但我必须先创建 MFiles 对象。

 ObjectVersionAndProperties objVersion = 
 mFilesStructure.MFileVault.ObjectOperations.CreateNewObject(objTypeID, 
 propValues);

 var testPropValues = new PropertyValues();
 testPropValues = FilesStructure.MFileVault.ObjectPropertyOperations.GetProperties(objVersion.ObjVer);

  var testPropValue = new PropertyValue();
  testPropValue = testPropValues.SearchForProperty(typeClientID);

它工作正常“testPropValue”具有正确设置的所有属性,尤其是 DataType...但不想首先创建 MFiles...

在我看来,这应该做同样的事情,但不会

var test = new PropertyDef();
test = mFilesStructure.MFileVault.PropertyDefOperations.GetPropertyDef(typeClientID);
var testPropValue = new PropertyValue();
testPropValue.PropertyDef = test.ID;

属性设置不正确...

任何人都可以提供帮助

最好的问候,

斯蒂芬

【问题讨论】:

    标签: c# m-files-api


    【解决方案1】:

    我只是偶然发现了这个,正在寻找其他东西,并认为我可能会有所帮助。

    你实际上有点倒退了。新对象的创建实际上是该过程的最后一步。您需要通过创建每个单独的 PropertyValue() 来创建 PropertyValues() 的集合,然后将它们添加到集合中。

    所以是这样的:

        public static PropertyValue GetPropertyValue(int propertyDefId, object value)
        {
            //resolve property def by ID
            PropertyDef propertyDef = Vault.PropertyDefOperations.GetPropertyDef(propertyDefId);
    
            //create the property value with prop def ID and value
            return GetPropertyValue(propertyDefId, propertyDef.DataType, value);
        }
    
        public static PropertyValue GetPropertyValue(int propertyDefId, MFDataType dataType, object value)
        {
            PropertyValue propertyValue = new PropertyValue();
            propertyValue.PropertyDef = propertyDefId;
            propertyValue.TypedValue.SetValue(dataType, value);
    
            return propertyValue;
        }
    
        public static ObjectVersionAndProperties CreateDocument(PropertyValues propertyValues, string filepath, Vault vault)
        {
            // Create the Source File object from the filepath.
            SourceObjectFile sourceFile = new SourceObjectFile();
            sourceFile.SourceFilePath = filepath;
            sourceFile.Extension = Path.GetExtension(filepath).TrimStart('.');
            sourceFile.Title = Path.GetFileNameWithoutExtension(filepath).TrimEnd('.');
    
            // Create the document object.
            return vault.ObjectOperations.CreateNewSFDObject((int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument,
                propertyValues, sourceFile, true);
        }
    

    一旦你设置了上述函数,你可以像这样调用它们:

         //If the document doesn't exist, go ahead and create a new one
         //creat and add all the properties
         PropertyValues props = new PropertyValues();
         //class
         props.Add(-1, HelperMF.GetClassPropertyValue(classId, env.Vault));
         //job
         int jobId = env.Vault.ValueListItemOperations.GetValueListItemByDisplayID(Structure.ObjType.Job.ID, jobDisplayId).ID;
         props.Add(-1, HelperMF.GetPropertyValue(Properties.Job.ID, jobId, env.Vault));
         //estimates
         props.Add(-1, HelperMF.GetPropertyValueFromListOfDisplayIds(env.Vault, Properties.Estimate.ID,
                          MFDataType.MFDatatypeMultiSelectLookup, Structure.ObjType.Estimate.ID, estimateDisplayIds));
         //Add the relationship to the return doc that was uploaded
         props.Add(-1, HelperMF.GetPropertyValue(Properties.Document.ID, movingDocId, env.Vault));
    
         //create the new object in the vault
         ObjectVersionAndProperties newDoc = HelperMF.CreateDocument(props, docDownloadPath, env.Vault);
    

    我使用了很多帮助函数和类,但您应该从我的示例中了解要点。另外,我强烈建议您使用 M-Files 社区网站进行研究,因为那里有很多专门针对 M-Files 的代码示例。

    https://community.m-files.com/

    另外,如果您还没有,请使用 API 文档,因为它还包含代码示例。

    http://www.m-files.com/api/documentation/2015.2/

    希望这会有所帮助, 迈克

    【讨论】:

      猜你喜欢
      • 2011-09-03
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2018-02-18
      • 2017-10-26
      • 2019-03-22
      相关资源
      最近更新 更多