Sourcesafe Automation Tips

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)

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);

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 />";
//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. 🙂


4 thoughts on “Sourcesafe Automation Tips

  1. Hi ,
    I have a requirement to do the VSS automation.I got so many examples but nothing is working fine , can you please help me on this.
    VSS v6.0
    Visual Studio 2005
    Thanks in advance

  2. Hi ,
    I want to show the vss Items in a tree view in C#.NET.There should be two more containers , in first container it should show the files of the folder which I have selected in treevie.And what ever files I will select from first container, it should go to the next container.

    Thanks in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s