Renaming a document version file in a script

You can rename a document version file using the script provided below.

Script without using PublicAPI.

For the script to work correctly, add the following assemblies:

EleWise.ELMA.Documents
EleWise.ELMA.Documents.Docflow

Namespaces:

using EleWise.ELMA.ConfigurationModel;
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Model.Common;
using EleWise.ELMA.Model.Entities;
using EleWise.ELMA.Model.Managers;
using EleWise.ELMA.Services;
 
In the example below, a document is stored in the context.Dok context variable, the script changes the name of the current document version file. 

Script text:

context.Dok.Versions.ToList().ForEach(v =>{ //view all the document versions
   if (v.Status == DocumentVersionStatus.Current) //if the version is current
   {
   v.File = v.File.Clone(); 
   v.File.Id = null;
   v.File.Uid = Guid.NewGuid();
   v.File.Name = "renamed.docx"; //change the file name
   v.Save();                                                        
   }
});
 
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

Context variable:

context.Document - variable of the Document type

Namespace:

using EleWise.ELMA.API;
 

Script:

PublicAPI.Docflow.DocumentVersion.RenameVersionFile(context.Document.CurrentVersion, "renamed", true); //Rename the document version while keeping the file version