Vault API tool - check if file is in vault.

Vault API tool - check if file is in vault.

Jef_E
Collaborator Collaborator
3,125 Views
4 Replies
Message 1 of 5

Vault API tool - check if file is in vault.

Jef_E
Collaborator
Collaborator

Hello there,

 

I'm new to the vault programming and would like to start with making a fairly easy ( correct me if i'm wrong ) tool. This tool will have as purpose: supporting the user in getting all data in the vault.

 

At my workplace we use Vault Basic since not so long. And some ( mostly the older users ) have difficulties putting the drawings into vault after creating them. If it's in vault they are consistant in checking the files into vault because the dialog says to do so.

 

So what I would like to do first: Check for all *.dwg files in a certain path if they also exist in vault.

Q: How do you check if a file is in vault based on the path?

 

Secondly i would like to check for the file status:

Q: How do you check the file status based on the file path?

 

If someone can help me how to start, or point me to a good tutorial or guide, that would be awesome.

We are currently using vault 2014.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
3,126 Views
4 Replies
Replies (4)
Message 2 of 5

Patrick.Gruber
Enthusiast
Enthusiast

Hello Jef_E,

I would suggest to you powerVault, it's a set of powerShell commandlets and you can write easly scripts. For instance of checking if a file exists you could script something like this:

 

 

$file = Get-VaultFile -File "$/Designs/Pad Lock/Test.dwg"
if($file -eq $null) {
   throw "File Test.dwg does NOT exist."
}

If you want to check the status of a file you could extend the script like:

 

$file = Get-VaultFile -File "$/Designs/Pad Lock/Test.dwg"
if($file -eq $null) {
   throw "File Test.dwg does NOT exist."
}
$fileStatus = $file._State
Write-Host "Status of Test.dwg is '$fileStatus'"

If you are interested in this free application go here http://coolorange.com/de/apps_vault.php the documentation you can find here: 

http://www.coolorange.com/wiki/doku.php?id=powervault

 

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 5

Anonymous
Not applicable

Here is some code you can maybe use? rewrite

 

I use it to check for pdfs when we create documentation where i merge several pdf files into one!

 

CheckIfFileExistInVault(Pdffilename & ".pdf")

 

Private Sub CheckIfFileExistInVault(ByVal VaultFileName As String)

 

Dim win As System.Security.Principal.WindowsIdentity

win = System.Security.Principal.WindowsIdentity.GetCurrent()

Dim UserName = win.Name '.Substring(win.Name.IndexOf("\") + 1)

Dim results As VDF.Vault.Results.LogInResult = VDF.Vault.Library.ConnectionManager.LogIn("Name of Vault server", "Name of vault", UserName, "", VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, Nothing)

Dim connection As VDF.Vault.Currency.Connections.Connection = results.Connection

If Not results.Success Then

'MsgBox("Login error")

Return

End If

If results.Success Then

'Start at the root Folder.

Dim root As VDF.Vault.Currency.Entities.Folder = connection.FolderManager.RootFolder

Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = Nothing

Try

' Get the FileIteration

oFileIteration = getFileIteration(VaultFileName, connection)

If oFileIteration Is Nothing Then

VaultFileIsExisting = False

VDF.Vault.Library.ConnectionManager.LogOut(connection)

Exit Sub

Else

'MsgBox("File found" &  vaultfilename)

VaultFileIsExisting = True

VDF.Vault.Library.ConnectionManager.LogOut(connection)

Exit Sub

End If

Catch ex As Exception

VDF.Vault.Library.ConnectionManager.LogOut(connection)

Exit Sub

End Try

End If

End Sub

 

Public Function getFileIteration(ByVal nameOfFile As String, ByVal connection As VDF.Vault.Currency.Connections.Connection) As VDF.Vault.Currency.Entities.FileIteration

Dim conditions As ACW.SrchCond()

ReDim conditions(0)

Dim lCode As Long = 1

Dim Defs As ACW.PropDef() = connection.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")

Dim Prop As ACW.PropDef = Nothing

For Each def As ACW.PropDef In Defs

If def.DispName = "File Name" Then

Prop = def

End If

Next def

Dim searchCondition As ACW.SrchCond = New ACW.SrchCond()

searchCondition.PropDefId = Prop.Id

searchCondition.PropTyp = ACW.PropertySearchType.SingleProperty

searchCondition.SrchOper = lCode

searchCondition.SrchTxt = nameOfFile

conditions(0) = searchCondition

' search for files

Dim FileList As List(Of Autodesk.Connectivity.WebServices.File) = New List(Of Autodesk.Connectivity.WebServices.File)()

Dim sBookmark As String = String.Empty

Dim Status As ACW.SrchStatus = Nothing

While (Status Is Nothing OrElse FileList.Count < Status.TotalHits)

Dim files As Autodesk.Connectivity.WebServices.File() = connection.WebServiceManager.DocumentService.FindFilesBySearchConditions(conditions, Nothing, Nothing, True, True, sBookmark, Status)

If (Not files Is Nothing) Then

FileList.AddRange(files)

End If

End While

Dim oFileIteration As VDF.Vault.Currency.Entities.FileIteration = Nothing

For i As Integer = 0 To FileList.Count - 1

If FileList(i).Name = nameOfFile Then

oFileIteration = New VDF.Vault.Currency.Entities.FileIteration(connection, FileList(i))

End If

Next

Return oFileIteration

End Function

 

Regards Kent boettger

0 Likes
Message 4 of 5

Jef_E
Collaborator
Collaborator

Is there a certain file that I need to reference in Visual Studio to get this to work? For Inventor there is a interop.dll file.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 5 of 5

Anonymous
Not applicable

try these

 

Imports Autodesk.Connectivity.WebServices

Imports Autodesk.Connectivity.WebServicesTools

Imports VDF = Autodesk.DataManagement.Client.Framework

Imports Autodesk.DataManagement.Client.Framework.Vault.Services

Imports Autodesk.DataManagement.Client.Framework.Vault.Currency.Connections

Imports ACW = Autodesk.Connectivity.WebServices

Imports Autodesk.Connectivity.Explorer.ExtensibilityTools

 

regards. kent boettger

0 Likes