I am currently playing with the Visual Sourcesafe Automation for implementation in one of my projects. I was trying to traverse the files of a specific project (aka folder) and the code in Visual Basic.NET works like this:
Dim vssDB As IVSSDatabase = New VSSDatabase
vssDB.Open("srcsafe.ini location", "username", "password")
Dim sfolder As VSSItem
sfolder = vssDB.VSSItem("$/MyProject").Items(True).Item(1)
Dim xItem As VSSItem
For Each xItem In sfolder.Items(False)
System.Diagnostics.Debug.Print(xItem.Name & " - " & xItem.VersionNumber)
'xItem.Checkout()
'xItem.Checkin()
'xItem.Get("c:\\temp1")
Next
If I want to perform some of the operations (such as check in/out), I just have to modify the lines in the for each loop to work. Since I am a C# developer, I translated the same code and it appears like this:
IVSSDatabase vssDB = new VSSDatabase();
vssDB.Open("srcsafe.ini location", "username", "password");
VSSItem sfolder;
sfolder = vssDB.VSSItem("$/MyProject").Items(true).Item(1);
VSSItem xItem;
foreach ( xItem in sfolder.Items(false)) {
System.Diagnostics.Debug.Print(xItem.Name + " - " + xItem.VersionNumber);
//xItem.Checkout();
//xItem.Checkin();
//xItem.Get("c:\\temp1");
}
What keeps me wondering is that the code for VB works while the one for C# had errors. Specifically on line 5, it triggers an error that the VSSItem is not supported by the language. I made a workaround on the structure and the working version is this:
IVSSDatabase vssDB = new VSSDatabase();
vssDB.Open("srcsafe.ini location", "username", "password");
VSSItem sfolder;
sfolder = (VSSItem)vssDB.get_VSSItem("$/MyWebsite", false);
foreach ( VSSItem xItem in sfolder.get_Items(false)) {
string outputdisplay = xItem.Name + " - " + xItem.VersionNumber + "<br />";
Response.Write(outputdisplay);
//xItem.Checkout("comments_here", "checkout_location", 0);
//xItem.Checkin("comments_here", "checkout_location", 0);
}
Since C# doesn’t accept optional parameters, you need to fill-in for the parameters. I hope this one helps and makes sense for those who are working on Sourcesafe Automation.