This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

The object has been checked out in M-Files, but the version you are attempting to access is not the current checked-out version. The issue is usually caused by outdated client e

//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);
}
}