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: 

Vault API - Get all properties from folder and sub folder within

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
worrawat_srisanpang
646 Views, 8 Replies

Vault API - Get all properties from folder and sub folder within

Hi

 

It's Vault 2023 SDK.

I'm trying to develop API to get properties of all files within one folder.

Root folder is "Drawings", but it has many sub folders inside.

 

Folder folder = mVault.DocumentService.GetFolderByPath("$/Drawings");
File[] filearray = mVault.DocumentService.GetLatestFilesByFolderId(folder.Id, true);

 

Need recommendation if there is any easier method to get all files name and id from all folders inside, or I have to keep looping looking for files for each folder

 

Also once list of files is acquired, there is need for user-defined metadata, which I don't know what method and how to retrieve it yet.

 

Please help, thanks.

 

 

Tags (1)
Labels (1)
8 REPLIES 8
Message 2 of 9

Hi

 

You could try using FindFilesBySearchConditions, setting the SrchCond to Folder Path Contains  "$/Drawings"

 

It's probably faster than looping through each folder, but it will depend on your Vault

 

To retrieve the metadata, you will need to use PropertyService.GetPropertiesByEntityIds if you want all the properties or PropertyService.GetProperties, if you know which properties you want.

 

To find the Property Definitions, use PropertyService.GetPropertyDefinitionsByEntityClassId.

 

Hope that helps

Nick

 

 

 

Message 3 of 9

Hi Nick,

 

Thank you.

Is there anyway to make this method FindFilesBySearchConditions return more than 500?
Because it seems to be at max 500 results

Message 4 of 9

Hi

 

FindFilesBySearchConditions returns files in batches, the batch size is set in Vault

 

You need to loop through to get the full set

 

You will find an example in the VaultBrowserSample in the SDK. Look in FinderForm.cs

 

This is the section you're looking for

 

List<File> fileList = new List<File>();

while (status == null || fileList.Count < status.TotalHits)
{
  File[] files = m_connection.WebServiceManager.DocumentService.FindFilesBySearchConditions(
    conditions, null, null, true, true,
    ref bookmark, out status);
    if (files != null)
      fileList.AddRange(files);
}

 

That should help you

Nick

Message 5 of 9

Hi Nick,

 

Thank you, it works.

One last question, is it possible to get user defined properties from FindFilesBySearchConditions

Or I have to loop to fetch properties with PropertyService.GetPropertiesByEntityIds for every file.

 

Because total files are more than 100K, so I want it to process faster.

 

Message 6 of 9

Hi

 

You can get the properties from multiple entities using GetPropertiesByEntityIds

 

Just pass in an array of all the entity IDs (from fileList in the previous example)

 

That will give you everything in a single call, but you may want to retrieve them as part of the while loop if the number of files found is very large - sometimes Vault doesn't perform well if you ask it to do too much in a single call.

 

Nick

Message 7 of 9

Hi Nick,

 

Thank you, I've finished the implementation.

Just my curiosity, while using FindFilesBySearchConditions, sometimes I found that one file, but it responses to me as 2 records, only different by state of lifecycle, Published and Work In Progress.

If I want to have only "Published" state with FindFilesBySearchConditions, is it possible? or do I need to filter after getting the data.

Message 8 of 9

Hi

 

If you are getting more than one version of a file, you must be setting latestOnly to false

 

To filter so that you just get “Published” states, you need to add another search condition of “State (Historical) = Published”

 

Nick

Message 9 of 9

Thank you, Nick.
It's all implemented.

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

Post to forums  

Autodesk Design & Make Report