HowTo Perform GetlatestVersion() through API

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

Post Reply
impact79
Posts: 6
Joined: Thu Jun 21, 2007 6:23 am

HowTo Perform GetlatestVersion() through API

Post by impact79 » Thu Jun 21, 2007 6:27 am

Hello,

i am new to the Vault API and have questions about how to accomplish a GetLatestVersion on a Repository subfolder.

Logging in into the server and setting the active repository already works, but how do i continue from here ?

Any help appreciated :)

Thanks,
impact79

jeremy_sg
Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear
Contact:

Post by jeremy_sg » Thu Jun 21, 2007 7:41 am

Which version of Vault are you using?

holdera
Posts: 6
Joined: Thu Jul 05, 2007 4:13 pm
Location: Nanaimo BC, Canada

Post by holdera » Thu Jul 05, 2007 4:24 pm

I used the get method of the ClientInstance object found in VaultClientOperationsLib. It is overloaded to work on a file, a folder or an array of files. I used the folder version to update all my files at once. make sure you understand what all the parameters do.

I didn't check the file out first or change its working directory, so it replaces all my local files with the most recent from the server. This is what I want, provided I am not currently working on anything in that directory. The params let you specify what to do with modified local files

Code: Select all

		myClient.Get(searchFolder,true,true,MakeWritableType.MakeAllFilesReadOnly,SetFileTimeType.Current,MergeType.AttemptAutomaticMerge,null);

Jinx
Posts: 4
Joined: Mon Jan 28, 2008 4:58 pm

Post by Jinx » Mon Jan 28, 2008 5:02 pm

I've tried this but I always get the error "Value cannot be null. Parameter name: path".

I tried passing in the last variable also to no avail... here's my test code I was trying just to see if I could get it to work:

Code: Select all

    Sub Main()

        Dim Client As New VaultClientOperationsLib.ClientInstance()        
        Client.Init(VaultClientNetLib.VaultConnection.AccessLevelType.Client, "c:\Temp")

        Client.Login("<<myserver>>", "<<myuser>>", "<<mypassword>>")

        Dim Ri() As VaultRepositoryInfo
        Client.ListRepositories(Ri)

        For Each Bleh As VaultRepositoryInfo In Ri
            If Bleh.RepName = "Default Repository" Then
                Console.WriteLine("Default Repository found, Id=" & Bleh.RepID)                
                Client.SetActiveRepositoryID(Bleh.RepID, Client.Connection.Username, Bleh.UniqueRepID, True, False)            
            End If
        Next

        Dim Vf As VaultClientOperationsLib.VaultClientFolder = Client.Repository.Root.FindFolderRecursive("$/ETA2/Interfaces/FTI Weekend Update/")

        Dim Cb As New VaultClientOperationsLib.PromptForOverwriteCallback(AddressOf Temp)
        Dim Op As New VaultClientOperationsLib.OverwritePrompt(MergeType.OverwriteWorkingCopy, Cb)

        Client.Get(Vf, False, True, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, Op)

    End Sub

    Function Temp() As Boolean
        Return True   ' :P
    End Function
I also tried this as the client.get line from another post I saw here passing in a null for the last option... am I missing setting a path somewhere, and if so, where?:

Code: Select all

        Client.Get(Vf, False, True, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, Nothing)
We're currently using 3.5.1 (4786)

jeremy_sg
Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear
Contact:

Post by jeremy_sg » Tue Jan 29, 2008 8:51 am

Try removing the trailing slash from the folder path.

Jinx
Posts: 4
Joined: Mon Jan 28, 2008 4:58 pm

Post by Jinx » Tue Jan 29, 2008 9:16 am

Tried that, it still gets the same error on the Client.Get line which is "Value cannot be null. Parameter name: path"

It appears to be downloading a bunch of config files and information from the vault but never completes the operation.

I don't know if this makes a difference or not but the references I've included on the project are VaultClientNetLib, VaultClientOperationsLib & VaultLib. I didn't see where I was using anything outside of those.

jeremy_sg
Posts: 1821
Joined: Thu Dec 18, 2003 11:39 am
Location: Sourcegear
Contact:

Post by jeremy_sg » Tue Jan 29, 2008 9:23 am

It's also possible that you're trying to do a get on a folder that doesn't have a working folder set. Try setting the working folder first.

Jinx
Posts: 4
Joined: Mon Jan 28, 2008 4:58 pm

Post by Jinx » Tue Jan 29, 2008 10:39 am

You're correct, after looking through the object browser I figured out how to set the working folder. Below is the final example code snippet that works for posterity. Thank you for your assistance, it's much appreciated!

Code: Select all

Imports VaultClientOperationsLib
Imports VaultLib

Module Module1

    Sub Main()

        Dim Client As New VaultClientOperationsLib.ClientInstance()        
        Client.Init(VaultClientNetLib.VaultConnection.AccessLevelType.Client, "c:\New")

        Client.Login("<<myserver>>", "<<myuser>>", "<<mypassword>>")

        Dim Ri() As VaultRepositoryInfo
        Client.ListRepositories(Ri)

        For Each Bleh As VaultRepositoryInfo In Ri
            If Bleh.RepName = "Default Repository" Then
                Console.WriteLine("Default Repository found, Id=" & Bleh.RepID)                
                Client.SetActiveRepositoryID(Bleh.RepID, Client.Connection.Username, Bleh.UniqueRepID, True, False)            
                Client.TreeCache.SetWorkingFolder("$/ETA2/Interfaces/FTI Weekend Update", "C:\New")
            End If
        Next

        Dim Vf As VaultClientOperationsLib.VaultClientFolder = Client.Repository.Root.FindFolderRecursive("$/ETA2/Interfaces/FTI Weekend Update")

        Client.Get(Vf, True, True, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, MergeType.OverwriteWorkingCopy, Nothing)

    End Sub

End Module

Post Reply