Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MFiles API设置属性值_C#_M Files Api - Fatal编程技术网

C# MFiles API设置属性值

C# MFiles API设置属性值,c#,m-files-api,C#,M Files Api,我正在使用MFiles API 我想将propertyDef传递给propertyValue 此代码正在运行。。。但是我必须先创建MFiles对象 ObjectVersionAndProperties objVersion = mFilesStructure.MFileVault.ObjectOperations.CreateNewObject(objTypeID, propValues); var testPropValues = new PropertyValues(); t

我正在使用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”正确设置了所有属性,特别是数据类型。。。但我不想一开始就创建MFiles

在我看来,这也应该如此,但事实并非如此

var test = new PropertyDef();
test = mFilesStructure.MFileVault.PropertyDefOperations.GetPropertyDef(typeClientID);
var testPropValue = new PropertyValue();
testPropValue.PropertyDef = test.ID;
属性设置不正确

任何人都可以帮忙

致以最良好的祝愿


斯蒂芬

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

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

比如说:

    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的代码示例

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

希望这有帮助, 迈克