//Updating Object file property with a new file content in Mfiles using COM API
//Searching for an object in mfiles using external id or other properties
//creating a foreach loop to serach through the response
foreach(ObjectVersion objectVersion in searchResults)
{
foreach(ObjectFile objectFile in objectVersion.Files)
{
var objID = new MFilesAPI.ObjID();
objID.SetIDs(
ObjType: (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument,
ID: objectVersion.ObjVer.ID);
// Check out the object.
var checkedOutObjectVersion = vault.ObjectOperations.CheckOut(objID);
// Create a property value to update.
var nameOrTitlePropertyValue = new MFilesAPI.PropertyValue
{
PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle
};
nameOrTitlePropertyValue.Value.SetValue(
MFDataType.MFDatatypeText, // This must be correct for the property definition.
"Invoice A-112-35"
);
// Update the property on the server.
vault.ObjectPropertyOperations.SetProperty(
ObjVer: checkedOutObjectVersion.ObjVer,
PropertyValue: nameOrTitlePropertyValue); //Setting object property to a new value
foreach(ObjectFile objectFile1 in checkedOutObjectVersion.Files)
{
vault.ObjectFileOperations.UploadFile(objectFile1.ID, objectFile1.Version, @"D:\PythonNotesForProfessionals.pdf"); //Setting Single File of an Object to the new file
}
// vault.ObjectFileOperations.AddFile(
//ObjVer: checkedOutObjectVersion.ObjVer,
//Title: "My test document",
//Extension: "pdf",
//SourcePath: @"D:\FinalTestSined1.pdf");
// Check the object back in.
vault.ObjectOperations.CheckIn(checkedOutObjectVersion.ObjVer);
}
}