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.
Solved by Daniel.Dulzo. Go to Solution.
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
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.FindFilesBySearchConditions( _
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
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
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.FindFilesBySearchConditions( _
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
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
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/FilePreviewPage.aspx?iterationId=778902
Thanks
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/hyperlink-maestro.html. Playing with the utility and looking through the source code will hopefully give you some insight into what you're trying to do. It's probably worth noting that links with a specific file itration ID can get stale quickly because they will always open to the same file version. You might want to keep this in mind, depending on how you're going to be using these links.
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.
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!!!
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.
Dear Daniel
Would you please clarify a bit how to determine the <PropDefId> of the particular property of known name?
As a keen Vault user Iām used to rely on system property <Provider> while searching manually.
Using the property I can easily separate āInventorā or āAutocadā files from all the rest.
Coud you please describe the practical steps to determine <PropDefId> for <Provider> file property.
Haven't found this info in VaultAPI.chm
Thanks in advance.
Hi MaxU77,
You can use the code found in this article on Doug's blog to either enumerate through the property definitions for each entity class or to search for a property definition based on a system name. The article is a bit older (it's for Vault 2011) but the concept is still sound.
To enumerate through all the PropDef's for a given entity type, you can follow code similiar to what's in the first section which makes use of the GetPropertyDefinitionInfosByEntityClassId() web service method. It'll return a collection of PropDefInfo objects, each of which will contain a PropDef. Alternatively, you can use the GetPropertyDefinitionsByEntityClassId() method to avoid having to access the PropDef object through the PropDefInfo objects. By looking through the collection of PropDef's you can find the property you want to use, along with its Id.
If want to find a property's Id using its system name, follow the description in the second section. Use the FindPropertyDefinitionsBySystemName() method to get a collection of PropDef's matching the specific ones you're looking for. Again, the Id's for the properties can be found on their respective PropDef objects.
Regards
Can't find what you're looking for? Ask the community or share your knowledge.