Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find Vaulted Filepath based on FileIteration

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
AlexFielder
1712 Views, 4 Replies

Find Vaulted Filepath based on FileIteration

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.

4 REPLIES 4
Message 2 of 5
AlexFielder
in reply to: AlexFielder

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.

Message 3 of 5
minkd
in reply to: AlexFielder

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

 



Dave Mink
Fusion Lifecycle
Autodesk, Inc.
Message 4 of 5
AlexFielder
in reply to: minkd

Thanks Dave, I shall make the necessary changes in the morning- seeing the mention of the inefficiency of my method; I can see exactly why yours will be faster. 🙂 Off to bed for me now.
Message 5 of 5
minkd
in reply to: AlexFielder

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



Dave Mink
Fusion Lifecycle
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report