msaa

Hi,

I'm having some real trouble with this one. I know there is a way to get the previous version of a file in C#, but I just can't seem to get it right. Here is what I am doing...

DateVersionSpec AfterCheckinDate = new DateVersionSpec(change.Item.CheckinDate);
DateVersionSpec BeforeCheckinDate = new DateVersionSpec(change.Item.CheckinDate.AddHours(-1));

//Download latest version
tfsVersionControl.DownloadFile(change.Item.ServerItem, 0, AfterCheckinDate, latestFile);

//Download yesterday's version
tfsVersionControl.DownloadFile(change.Item.ServerItem, 0, BeforeCheckinDate, dayOldFile);

It errors out on the change.Item.CheckinDate.AddHours(-1) line. I'm pretty sure it's because a version does not exist for that specific time.

Is there a way I can just retrieve the last VERSION of the file without specifying a time

Thank You,
Sam


Re: Team Foundation Server - Version Control Previous Version of a file (C#)What

Richard Berg MSFT

What error do you get TFS shouldn't throw an error there. You can create a DateVersionSpec with any date you like. It's defined as the highest changeset # that occured at or before that time. Maybe it's the .net framework Date class that's complaining.

The easiest way to get 2nd-to-latest version of a file is QueryHistory() with stopAfter=2.






Re: Team Foundation Server - Version Control Previous Version of a file (C#)What

msaa

You are absolutely correct.

Thanks a million!

I guess after about 12 hours of staring at a computer, your brain does kind of get fried.