Autodesk Vault Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I need to run the search criteria and get the results using VB code.
Here is the search criteria
File Name Contains SrchFile and
Latest Released Revision Is True
If there is a example of VB /c# code to do this?
Your help is appreciated.
Solved! Go to Solution.
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Dear shashipatra,
The Vault SDK comes packaged with some example projects in both VB and C Sharp. Specifically, the Vault File Browser example has a form that performs a search in Vault using various search conditions. I would suggest you look thought this code to see how to search for files in Vault.
Regards,
Daniel Dulzo

Daniel Dulzo
Software Engineer
Autodesk, Inc.
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I was able to come up with following code :
How do i add one more condition for
Latest Released Revision Is True
I know the PropID for Latest Released Revision Property is 22 but whats the condition code for 'Is True' ?
Dim SrcCond AsNew SrchCond
' search for files
Dim fileList As List(Of File) = New List(Of File)()
Dim bookmark AsString = String.Empty
Dim status As SrchStatus = Nothing
With SrcCond
.PropDefId = 8
.SrchOper = 1
.PropTyp = PropertySearchType.SingleProperty
.SrchTxt = "488278"
EndWith
'Create a search condition array
Dim SrcConds(0) As SrchCond
SrcConds(0) = SrcCond
While (status IsNothingOrElse fileList.Count < status.TotalHits)
Dim files As File() = m_serviceManager.DocumentService.FindFilesBySearch
SrcConds,
Nothing, Nothing, True, True, bookmark, status)
If (Not files IsNothing) Then
fileList.AddRange(files)
EndIf
EndWhile
If (fileList.Count > 0) Then
'iterate through found files and display them in the search results list box
ForEach file As File In fileList
'create the list item that will wrap the File
Dim fileItem As ListBoxFileItem = New ListBoxFileItem(file)
m_searchResultsListBox.Items.Add(fileItem)
Next file
Else
EndIf
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
There isn't a search operation for "is true." Instead, you use the operation "is exactly (or equals)" and set the search text to "True" or "False" (it is probably best to use Boolean.TrueString or Boolean.FalseString). For example:
Dim searchCondition As SrchCond = NewSrchCond()
searchCondition.PropDefId = 22 'haven't confirmed this is the right propdef id
searchCondition.PropTyp = PropertySearchType.SingleProperty
searchCondition.SrchOper = 3
searchCondition.SrchRule = SearchRuleType.Must
searchCondition.SrchTxt = Boolean.TrueString
You can find more information about different search operation codes and which property data types they are valid for by looking at the SDK's documentation for the SrchCond.SrchOper field. The documentation can be found under the docs directory in the install directory of the Vault SDK itself.
Regards,
Daniel Dulzo

Daniel Dulzo
Software Engineer
Autodesk, Inc.
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I added the codes but results in showing everything from Vault :
My condition is File Name contains "488278" and Latest Released Revision is True :
Dim SrcCond AsNew SrchCond
' search for files
Dim fileList As List(Of File) = New List(Of File)()
Dim bookmark AsString = String.Empty
Dim status As SrchStatus = Nothing
With SrcCond
.PropDefId = 8
.SrchOper = 1
.PropTyp = PropertySearchType.SingleProperty
.SrchTxt = "488278"
EndWith
'Create a search condition array
Dim SrcConds(0) As SrchCond
SrcConds(0) = SrcCond
With SrcCond
.PropDefId = 22
.SrchOper = 3
.PropTyp = PropertySearchType.SingleProperty
.SrchRule = SearchRuleType.Must
.SrchTxt = Boolean.TrueString
EndWith
Array.Resize(SrcConds, SrcConds.Length + 1)
SrcConds(SrcConds.Length - 1) = SrcCond
While (status IsNothingOrElse fileList.Count < status.TotalHits)
Dim files As File() = m_serviceManager.DocumentService.FindFilesBySearch
SrcConds,
Nothing, Nothing, True, True, bookmark, status)
If (Not files IsNothing) Then
fileList.AddRange(files)
EndIf
EndWhile
If (fileList.Count > 0) Then
'iterate through found files and display them in the search results list box
ForEach file As File In fileList
'create the list item that will wrap the File
Dim fileItem As ListBoxFileItem = New ListBoxFileItem(file)
m_searchResultsListBox.Items.Add(fileItem)
Next file
Else
EndIf
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
It looks as though your code below might have a programming error. It appears you're accidentally using the same SrchCond object for both search conditions in your array. I would assume your search is then returning of the latest revisions of all files in your Vault. Try initializing your search condition array differently. One possible solution might be as follows:
Dim SrcCond As New SrchCond
With SrcCond
.PropDefId = 8
.SrchOper = 1
.PropTyp = PropertySearchType.SingleProperty
.SrchTxt = "488278"
End With
Dim SrcCond2 As New SrchCond
With SrcCond2
.PropDefId = 22
.SrchOper = 3
.PropTyp = PropertySearchType.SingleProperty
.SrchRule = SearchRuleType.Must
.SrchTxt = Boolean.TrueString
End With
'Create a search condition array
Dim SrcConds(1) As SrchCond
SrcConds(0) = SrcCond
SrcConds(1) = SrcCond2
Hopefully after this change, your search will behave as expected.
Regards,
Daniel Dulzo

Daniel Dulzo
Software Engineer
Autodesk, Inc.
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks . That works great. Now i get the correct file names.
Is there a way to launch the latest released revision on the Vault web client like below?
The link has a IterationID passed to the FilePreciewPage.aspx. How i can get IterationID using the fileName.
http://VaultServer/AutodeskDM/webclient/FilePrevie
Thanks
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I'd like to make a quick correction about the SrchTxt field when searching on boolean properties. Due to possible localization issues, it's actually best to use "0" and "1" as false and true values because the text strings used for these values will, of course, differ based on language. By sticking with "0" and "1", you can avoid issues that might occur if your client and server are in different languages.
To answer your question about creating hyperlinks for the web clients, I'd like to direct you to the Vault Customization blog, Just Ones and Zeros, maintained by Doug Redmond. He has a utility for creating links that sounds pretty similar to what you're trying to do here: http://justonesandzeros.typepad.com/blog/2011/06/h
The iteration ID is the Id field on the Autodesk.Connectivity.WebService.File class. I've also answered this question on the other thread you've created so that future user will be able to locate the answer more easily.

Daniel Dulzo
Software Engineer
Autodesk, Inc.
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I noticed that i get different results when using the Web Client Search and Windows API Search.
My Web Client Search Condition is
File Name Contains 488278
Latest Released Version is True
My API code which i have posted above using the same condition but why i am getting different results.
When i say different results , number of resulting files are different and file.id (Iteration ID) are different.
I did chaneg boolean.Tostring to '1' but still i am getting different results.
HELP!!!
Re: Searching for Files by Criteria - VB .Net using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
The results might differ because your code above seems to be setting the latestOnly parameter of the FindFilesBySearchConditions() method to true. If your search using the web client is including all versions of files, this would likely cause the number of files found to differ between the two searches. I would suggest looking at the SDK documentation for the FindFilesBySearchConditions() method, as more information can be found there.

Daniel Dulzo
Software Engineer
Autodesk, Inc.


