Skip to main content

Add a version to an existing file

You can version the document in the DM with the code at the bottom.

public void BtnVersiyon_OnClick(Object sender, EventArgs e)
{

int frmID = 1254; You can get it in the form of Document1.ProfileId in the stream.
eBAForm frm = new eBAForm(frmID);
string filename = "";
string filePath = "";
Stream str = null;
eBAConnection con = CreateServerConnection();
Con. open();

Try
{
Con. open();
DMFile df = con. FileSystem.GetFile("workflow/SampleProject/Form/" + frmID + ".wfd");
DMCategoryContentCollection SourceAttachments = df. GetAttachments("Category1");
DMFileContent fl = SourceAttachments[0];
filename = fl. ContentName;

str = df. CreateAttachmentContentDownloadStream("Category1", filename);
filePath = "Education/" + filename;
if (!con. FileSystem.HasFile(filePath))
{
DMFile newFile = con. FileSystem.CreateFile(filePath);
newFile.Upload(str);

/*
You can use the following code to give version 1 when first throwing. Its use is not mandatory. It can also be discarded without giving a version.
DMCreateFileParameters dcfp = new DMCreateFileParameters();
DMVersion vrs = new DMVersion(1, 0);
DCFP. Version = vrs;
DMFile newFile = con. FileSystem.CreateFile(filePath, dcfp);
newFile.Upload(str);
*/
}
else
{
DMFile versionFile = con. FileSystem.CreateFileMajorVersion(filePath); To give a major version
versionFile.Upload(str);
versionFile.SetPublishedVersion(versionFile.Version);
/*
DMFile vrsFile = con. FileSystem.CreateFileMinorVersion(filePath); To give a minor version
vrsFile.Upload(str);
vrsFile.SetPublishedVersion(vrsFile.Version);

*/

ShowMessageBox("Version addition successful");
}
}
finally
{
Con. Close();
}

}