Do a search for a specific File using API

This forum is now locked, since Gold Support is no longer offered.

Moderator: SourceGear

Locked
realtytrac
Posts: 34
Joined: Wed Jun 15, 2005 2:07 pm

Do a search for a specific File using API

Post by realtytrac » Tue Sep 06, 2005 4:23 pm

Hi,

Using the API, i need to search by a file's path in Vault, and pull back all versions of it, with comments. Basically, i want to see every time an item has been checked in, the version of the file when it was checked in, and the comment added when checked in.

Could you please provide me with some code or examples to help me out.

Thank you

Haider

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Wed Sep 07, 2005 9:19 am

The best way to get started is to look at the command line client source code, available in the Client API installer or zip file, at http://www.sourcegear.com/vault/downloads.html

For what you are looking for, the source for retrieving history in the command line client will probably get you most of the way there.
Last edited by dan on Wed Sep 07, 2005 10:17 am, edited 1 time in total.

realtytrac
Posts: 34
Joined: Wed Jun 15, 2005 2:07 pm

Post by realtytrac » Wed Sep 07, 2005 9:51 am

Hi dan,

That link you gave me is not working. I have already looked at client code too.

This is what i have so far:

ushort ObjPropFolderMask = 0x0001;
// ushort ObjPropFileMask = 0x0002;
// ushort ObjPropBranchMask = 0x0004;
// ushort ObjPropSnapshotMask = 0x0008;
// ushort ObjPropVirtualMask = 0x0010;
string regExp = "";
string [] filePaths = {FilePath};
VaultLib.VaultHistoryQueryRequest req = new VaultLib.VaultHistoryQueryRequest();
DateTime now = DateTime.Now;
ArrayList users = new ArrayList();
ArrayList substrings = new ArrayList();
ArrayList myList = new ArrayList();
VaultVDDItem newItem;
long objVerID = 0;
ArrayList actions = new ArrayList();
ArrayList sorts = new ArrayList();
sorts.Add((long)VaultQueryRequestSort.NameSort);
sorts.Add((long)VaultQueryRequestSort.DescSort);
sorts.Add((long)VaultQueryRequestSort.AscSort);
sorts.Add((long)VaultQueryRequestSort.VersionSort);

req.SubstringType = VaultLib.VaultQueryRequestSubstrings.FileFolderNames;
req.Substrings = filePaths;
req.IsFolder = true;
req.Recursive = true;

req.DateFilterType = VaultQueryRequestDateTypes.DoNotFilter;
req.DateFilterMask = VaultQueryRequestDates.DoNotFilter;
actions.Clear();
req.CommentFilter = VaultLib.VaultQueryRequestComments.AnyComment;
//req.CommentSubstring= VDDNumber;

req.RepID = _myClient.ActiveRepositoryID;
req.TopName = "$";

req.Recursive = true;
req.Users = (VaultLib.VaultUser[]) users.ToArray(typeof(VaultLib.VaultUser));
req.Actions = (long[]) actions.ToArray(typeof(long));
req.Sorts = (long[]) sorts.ToArray(typeof(long));

string token = String.Empty;
int rowsRetrieved = 0;
VaultLib.VaultHistoryItem[] items = new VaultLib.VaultHistoryItem[1];
_myClient.Connection.HistoryBegin(req, 500, ref rowsRetrieved, ref token);

if (rowsRetrieved > 0)
{
_myClient.Connection.HistoryFetch(token, 0, rowsRetrieved - 1, ref items);
}
_myClient.Connection.HistoryEnd(token);


This code works for file extensions maybe, and it also works for filenames (say hello.txt), but when i try to do it for a specific file's path (say $\Website\hello.txt), it doesn't work. The FilePath variable is where i am trying to find a specific file in Vault.

How can i modify my code above to get that.

Thanks

Haider

dan
Posts: 2448
Joined: Wed Dec 17, 2003 5:03 pm
Location: SourceGear
Contact:

Post by dan » Wed Sep 07, 2005 10:27 am

If you know the name of the file you want, try using it in the Req.TopName instead of the req.Substrings args, which you would then ignore. I think TopName can be a file name, and I think the substrings is for searching only on file names that match the string, and does not allow file path matching.

I have to admit that I'm guessing a little. If that doesn't help, I'll have to actually get the compiler out :)

realtytrac
Posts: 34
Joined: Wed Jun 15, 2005 2:07 pm

Post by realtytrac » Wed Sep 07, 2005 12:10 pm

yes, thanks a lot. that worked. That brought me back the history of that specific filepath.

thanks

Locked