views:

1617

answers:

4

I need to get a file from sourcesafe database programmatically. Any idea of how to do it?

ps: I'll do that by using C#.

+1  A: 

There is a command-line SS.EXE program that you can call to do source control operations. However, it relies on global SourceSafe configuration and so it sometimes is hard to make it do what you want.

Greg Hewgill
+1  A: 

There is an OLE library for VSS

You might want to look at this discussion.

Omar Kooheji
+6  A: 
using System;
using System.Collections.Generic;
using SourceSafeTypeLib;

namespace YourNamespace
{

public class SourceSafeDatabase 
{
    private readonly string dbPath;
    private readonly string password;
    private readonly string rootProject;
    private readonly string username;
    private readonly VSSDatabaseClass vssDatabase;

    public SourceSafeDatabase(string dbPath, string username, string password, string rootProject)
    {
        this.dbPath = dbPath;
        this.username = username;
        this.password = password;
        this.rootProject = rootProject;

        vssDatabase = new VSSDatabaseClass();
    }  

    public List<string> GetAllLabels()
    {
        List<string> allLabels = new List<string>();

        VSSItem item = vssDatabase.get_VSSItem(rootProject, false);
        IVSSVersions versions = item.get_Versions(0);

        foreach (IVSSVersion version in versions)
        {
            if (version.Label.Length > 0)
            {
                allLabels.Add(version.Label);
            }
        }

        return allLabels;
    }

    public void GetLabelledVersion(string label, string project, string directory)
    {
        string outDir = directory;
        vssDatabase.get_VSSItem(rootProject, false).get_Version(label).Get(ref outDir, (int)VSSFlags.VSSFLAG_RECURSYES + (int)VSSFlags.VSSFLAG_USERRONO);
    }

    public void Open()
    {
        vssDatabase.Open(dbPath, username, password);
    }

    public void Close()
    {
        vssDatabase.Close();
    }

}


// some other code that uses it

SourceSafeDatabase sourceControlDatabase = new sourceControlDatabase(...);
sourceControlDatabase.Open();
sourceControlDatabase.GetLabelledVersion(label, rootProject, projectDirectory);
sourceControlDatabase.Close();
solrev
Thanks for code sample. I'll try it then be right back to you.
yapiskan
good luck. let me know if you want any more help. and thanks to whoever fixed my formatting. i did try to make it look ok but failed and gave up!
solrev
A: 

I want to list down all the user who has checked-out some files along with the file name with VSS path and with their local path. I need to send that list to the whole team stating thses all files are check out from this this user at this this location. Can we have any code for this??

BB Agrawal