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

Replace existing file

Hey, 

I am developing a VAF that I would like to replace an existing file with a new file. I am using the below code but I am having some issues. 

I firstly Check out the existing document (ReplacePDF) I am calling GetFilesForModificationInEventHandler, then calling ReplaceFiles and finally Check in the document. 

The file newObjectSourceFiles is the new file that I want to replace. 

var newObjVer = env.Vault.ObjectOperations.CheckOut(ReplacePDF.ObjVer.ObjID);
env.Vault.ObjectFileOperations.GetFilesForModificationInEventHandler(newObjVer.ObjVer);

env.ObjVerEx.ReplaceFiles(newObjectSourceFiles);
env.Vault.ObjectOperations.CheckIn(newObjVer.ObjVer);

Thank you

  • I would personally use EndRequireCheckOut here (you're using StartRequireCheckOut, so you may as well use the safety that EndRequireCheckOut gives).

    I can't see anything obvious that is wrong here.  Do you get an error?  Are you sure that the workflow is not set on the ReplacePDF object?  Is it possible that the data you've given (workflow alias, state ID) is incorrect?  Is it possible that some other event handler is firing on the "ReplacePDF" object that is affecting this?  Is the transaction definitely committed (e.g. can you see the new file and company property changes)?

  • Nothing Happens. 

    I can see the new file but with no property changes. I removed the change workflow property to check whether I get the property changes but nothing changes. So I now have these: 

    var objVerEx = new ObjVerEx(env.Vault, ReplacePDF.ObjVer);
    var b = objVerEx.StartRequireCheckedOut();
    objVerEx.ReplaceFiles(newObjectSourceFiles);
    objVerEx.SetProperty("PD.HSQEDocumentTitle", MFDataType.MFDatatypeText, "THIS IS TEST");
    objVerEx.EndRequireCheckedOut(b, env.CurrentUserID);

  • ARGH!

    Sorry, of course.

    If you're using ObjVerEx then you must call SaveProperties to persist the changes to the server:

    var objVerEx = new ObjVerEx(env.Vault, ReplacePDF.ObjVer);
    var b = objVerEx.StartRequireCheckedOut();
    objVerEx.ReplaceFiles(newObjectSourceFiles); //Replace the file 
    
    // These only change IN MEMORY.
    objVerEx.SetWorkflowState("WF.HsqeWorkflow", 132); //Change the wokflow 
    objVerEx.SetProperty("PD.Company", MFDataType.MFDatatypeMultiSelectLookup, 673); //Set up a property
    
    // Save all changes to the server.
    objVerEx.SaveProperties();
    objVerEx.CheckIn(); //Check In the object 

  • Yes that was it Slight smile

    Great thank you Craig!