Vault Customization

Vault Customization

Reply
Contributor
shashipatra
Posts: 17
Registered: ‎03-16-2012
Message 1 of 12 (1,830 Views)
Accepted Solution

Searching for Files by Criteria - VB .Net using API

1830 Views, 11 Replies
03-19-2012 04:37 AM

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.

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

Employee
Daniel.Dulzo
Posts: 61
Registered: ‎05-25-2011
Message 2 of 12 (1,828 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-19-2012 07:37 AM in reply to: shashipatra

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.
Contributor
shashipatra
Posts: 17
Registered: ‎03-16-2012
Message 3 of 12 (1,829 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-19-2012 11:03 AM in reply to: 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


 

Employee
Daniel.Dulzo
Posts: 61
Registered: ‎05-25-2011
Message 4 of 12 (1,825 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-19-2012 12:09 PM in reply to: shashipatra

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.
Contributor
shashipatra
Posts: 17
Registered: ‎03-16-2012
Message 5 of 12 (1,821 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-19-2012 12:15 PM in reply to: 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

Employee
Daniel.Dulzo
Posts: 61
Registered: ‎05-25-2011
Message 6 of 12 (1,820 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-19-2012 12:38 PM in reply to: shashipatra

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.
Contributor
shashipatra
Posts: 17
Registered: ‎03-16-2012
Message 7 of 12 (1,807 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-20-2012 06:50 AM in reply to: 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

 

 

 

 

 

Employee
Daniel.Dulzo
Posts: 61
Registered: ‎05-25-2011
Message 8 of 12 (1,797 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-20-2012 07:39 AM in reply to: shashipatra

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.

 



Daniel Dulzo
Software Engineer
Autodesk, Inc.
Contributor
shashipatra
Posts: 17
Registered: ‎03-16-2012
Message 9 of 12 (1,792 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-20-2012 09:49 AM in reply to: Daniel.Dulzo

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!!!

Employee
Daniel.Dulzo
Posts: 61
Registered: ‎05-25-2011
Message 10 of 12 (1,776 Views)

Re: Searching for Files by Criteria - VB .Net using API

03-21-2012 08:02 AM in reply to: shashipatra

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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.