By Wayne Brill
If you have used the Vault API to Check-out / Check-in a file you may have noticed a status on the file of "Incorrect version Refresh the file" or “Edited out of turn” in Vault Explorer.
"Incorrect version Refresh the file"
In vault explorer a file is checked out to the working folder, modified there, and then checked in. Because of this, the latest checked in file matches the file in the working folder. If your code puts the file in a different directory the version in your working folder is never updated and the status is telling you that what you have on disk is not the latest version in vault.
“Edited out of turn”
The “Edited out of turn” status occurs when the create date of the local file does not match the create date of the File object in the vault. This blog post has more detail about this.
Example code:
Download Vault_CheckIn_CheckOut
Below is code from this project that avoids both of these conditions. To use this example the first file in the root folder of the vault needs to be a txt file. (or change the code so that it uses a txt file).
private void button2_Click(object sender, EventArgs e)
{
if (m_serviceManager != null )
{
Folder rootFolder =
m_serviceManager.DocumentService.GetFolderRoot();
File[] rootFolderFiles =
m_serviceManager.DocumentService.
GetLatestFilesByFolderId(rootFolder.Id, true);
if (rootFolderFiles == null ||
rootFolderFiles.Length == 0)
return;
File file = rootFolderFiles[0];
ByteArray byteArray;
string localPath =
m_vaultExplorer.GetWorkingFolder(rootFolder);
//Check out the file
m_serviceManager.DocumentService.
CheckoutFile(rootFolder.Id,
file.Id,
CheckoutFileOptions.Master,
Environment.MachineName,
localPath, "test check-out",
DownloadOptions.Download,
false, out byteArray);
string filePath =
System.IO.Path.Combine(localPath, file.Name);
//Make readonly false for file
System.IO.FileInfo localFileInfo =
new System.IO.FileInfo(filePath);
localFileInfo.IsReadOnly = false;
// edit the file
System.IO.File.WriteAllBytes
(filePath, byteArray.Bytes);
System.IO.File.AppendAllText
(filePath, Environment.NewLine +
"Hello World_wB!");
// check in the file.
byteArray.Bytes =
System.IO.File.ReadAllBytes(filePath);
file = m_serviceManager.DocumentService.
CheckinFile(file.MasterId,
"test check-in wB", false,
System.IO.File.GetLastWriteTime
(filePath), null, null, true,
file.Name, file.FileClass,
file.Hidden, byteArray);
// avoid the "Edited-out-of-turn"
// icon in Vault Explorer
System.IO.FileInfo info =
new System.IO.FileInfo(filePath);
info.CreationTime = file.CreateDate;
info.Attributes =
info.Attributes |
System.IO.FileAttributes.ReadOnly;
}
}