0

I have a project with Visual Source Safe (VSS) and I need to append lines to a ".sql" file. I am trying to use the obvious code:

using (StreamWriter sw = File.AppendText(lblSourceFile.Text))
{
    sw.WriteLine("text here");
}

But I am getting "File Access" error because the file is not checked out in the VSS. Is there a way to programmaticlly check-out the file for edit and check it back in when finish ? All links I found are using VSSDatabaseClass, and I don't how to add reference for SourceSafetypelib dll and use VSSDatabaseClass...

Liran Friedman
  • 4,027
  • 13
  • 53
  • 96

2 Answers2

1

You can add ssapi.dll, which can be found in the installation folder of VSS, as reference and then you can use SourceSafetypelib. Here you can see a sample.

Community
  • 1
  • 1
Rachel
  • 1,372
  • 1
  • 8
  • 11
  • Can you please tell me whre do I bring the ctor parameters from ? `SourceSafeDatabase sourceControlDatabase = new SourceSafeDatabase("dbPath", "username", "password", "rootProject");` I have my username ans pwd, but where do I get the other two: dbpath and rootProject ? – Liran Friedman Mar 12 '14 at 12:49
  • I got it: `using SourceSafeTypeLib; VSSDatabaseClass vssDatabase = new VSSDatabaseClass(); vssDatabase.Open("VSS database path", "userName", "password"); VSSItem item = vssDatabase.get_VSSItem("file path as shown in vss", false); item.Checkout("Comments", item.LocalSpec, 0); using (StreamWriter sw = File.AppendText(lblSourceFile.Text)) { sw.WriteLine("text"); } item.Checkin("Comments", item.LocalSpec, 0); vssDatabase.Close();` thanks. – Liran Friedman Mar 12 '14 at 14:25
0

Thanks to Rachel for the ssapi.dll file. Here is the code that worked for my:

 using SourceSafeTypeLib;
 VSSDatabaseClass vssDatabase = new VSSDatabaseClass();
 vssDatabase.Open("VSS database path", "userName", "password");
 VSSItem item = vssDatabase.get_VSSItem("file path as shown in vss", false);
 item.Checkout("Comments", item.LocalSpec, 0);
 using (StreamWriter sw = File.AppendText(lblSourceFile.Text))
 {
     sw.WriteLine("text");
 }
 item.Checkin("Comments", item.LocalSpec, 0);
 vssDatabase.Close();
Liran Friedman
  • 4,027
  • 13
  • 53
  • 96