Vault API - how to search for particular file

Vault API - how to search for particular file

Anonymous
Not applicable
3,046 Views
3 Replies
Message 1 of 4

Vault API - how to search for particular file

Anonymous
Not applicable

I want to check if the file name already exists in Vault. I create a new string with new file name. Tried to use FindFilesBySearchConditions() with the following settings:

 

            Autodesk.Connectivity.WebServices.SrchCond searchCondition = new Autodesk.Connectivity.WebServices.SrchCond();
            searchCondition.PropDefId = 95;
            searchCondition.PropTyp = PropertySearchType.SingleProperty;
            searchCondition.SrchOper = 3;
            searchCondition.SrchTxt = "544-0002-Nebojsa_2.xlsx";

 

but I am getting no hits although there is one file with this name. I have read a few posts here and online about using FindFilesBySearchConditions() but still need clarification. What exactlt I need to do in setup to successfully use FindFilesBySearchConditions() in my file search? If you can provide a code example it would be appreciated. Thank you.

0 Likes
3,047 Views
3 Replies
Replies (3)
Message 2 of 4

Patrick.Gruber
Enthusiast
Enthusiast

Hi nebojsa.karadzic,

I have just made a quick example for you, it is written in powerShell and I have used powerVault (which is completly free!!):

 

Open-VaultConnection

function Get-FilesInVaultByName($fileName) {
    $propDef = $vault.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE") | where { $_.DispName -eq "Name"}
    $searchCondition = new-Object Autodesk.Connectivity.WebServices.SrchCond
    $searchCondition.PropDefId = $propDef.Id
    $searchCondition.PropTyp = [Autodesk.Connectivity.WebServices.PropertySearchType]::SingleProperty
    $searchCondition.SrchOper = 3
    $searchCondition.SrchTxt = $fileName

    $rootFolder = $vault.DocumentService.GetFolderRoot()
    $searchStatus = new-object Autodesk.Connectivity.WebServices.SrchStatus
    $files = $vault.DocumentService.FindFilesBySearchConditions(@($searchCondition), @(), @($rootFolder.Id), $true, $true, [ref]$null, [ref]$searchStatus)
    return $files
}

Get-FilesInVaultByName "Pad Lock.iam"
Please mark this response as "Accept as Solution" if it answers your question.
If you have found any post to be helpful, even if it's not a direct solution, then please provide that author kudos!
😉
The author,
Patrick

coolOrange
www.coolOrange.com
0 Likes
Message 3 of 4

arvindDWSMZ
Explorer
Explorer

Hello Patrick,

 

Your post was very useful. I find that the FindFilesBySearchConditions function returns only system details of the files- things like date created, size, file name etc and not any custom properties for the file(s). If i have custom properties setup for every file(for eg. Collection Label or a Description field), how can i get those values from the FindFilesBySearchConditions function ? or any other way ?

 

Thanks

Arvind

0 Likes
Message 4 of 4

Markus.Koechl
Autodesk
Autodesk

I just answered in another thread the same question: you need one more call to get all properties for the files in your result set. https://forums.autodesk.com/t5/forums/replypage/board-id/301/message-id/6703 

In short: you need to search for files by search conditions and retrieve the properties based on this in a second step (for all files in the result in one single).



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes