Hi Folks,
Based on my previous post does anyone have an API sample they can share which shows how to retrieve the filepath of a FileIteration object?
Thanks,
Alex.
Solved! Go to Solution.
Solved by AlexFielder. Go to Solution.
As usual, after posting the question and perusing of the SDK Docs I have managed to find the answer and solved this issue myself:
This page (found via a google search) had the basis of what I needed: https://github.com/mberntsen/AddStepFile/blob/master/AddStepFileAction.cs
To wit, I needed to use FindFilePathsByNameAndChecksum() and the above page used it thus:
FilePath [] filepaths = ServiceManager.DocumentService.FindFilePathsByNameAndChecksum(iptiamfile.Name, iptiamfile.Cksum); String iptiampath = filepaths[0].Path.Replace("$", "C:/Vault WorkingFolder");
I have modified my code so it now looks like the following and, barring another replace of "/" with "\" looks like:
foreach (File file in fileList) { ListBoxFileItem fileItem = new ListBoxFileItem(new VDF.Vault.Currency.Entities.FileIteration(m_conn, file)); //long folderId = VDF.Vault.Currency.Entities FilePath[] filepaths = m_conn.WebServiceManager.DocumentService.FindFilePathsByNameAndChecksum(file.Name, file.Cksum); String iptiampath = filepaths[0].Path.Replace("$", "C:\\Vault Working Folder"); fileItem.Folder = iptiampath.Replace("/","\\"); Globals.ThisAddIn.NoMatch = false; Globals.ThisAddIn.selectedfile = fileItem; //we should only be returning one file because we're searching for it directly! return; }
So hopefully, this will aid someone else in future.
That is is very inefficient way to get the path.
A better way to get the vault path of a file:
If you don't already have a file object, use GetFileById to get it.
Folder folder = svcmgr.DocumentService.GetFolderById(file.FolderId);
string filePath = folder.FullName + "/" + file.Name;
-Dave
Also, if you are dealing with a list of files and there is a reasonable chance that some of them reside in the same folder, you should get the unique folderIds from your set of files and make just one call to GetFoldersByIds, putting the result in a dictionary.
For instance:
List<File> myFiles; // your list of files
Dictionary<long, Folder> foldersByIds = svcmgr.DocumentService.GetFoldersByIds(
myFiles.Select(f => f.FolderId).Distinct().ToArray()
).ToDictionary(f => f.Id);
foreach (var f in myFiles)
{
string filepath = foldersByIds[f.FolderId].FullName + "/" + f.Name;
}
-Dave