Archive for the 'Sourcesafe' Category

Building Some Web TreeViews

The TreeView control in ASP.NET 2.0 is used to display hierarchical data, such as table of contents or file directory in a tree structure. In most applications that I do, I use the TreeView control to show file directory structure. I was able to create a class that populates a TreeView provided with a physical directory structure residing on the same computer as to where the server is running. Rename the file below to .dll and use it as a reference on your web application. Once added to your web application usage would be:


using System;
// include other namespaces as needed
using PhysicalTreeView;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string location;
        pTreeView ptv = new pTreeView(location);
        // the example below is valid without specifying the "isWeb" to false.
        pTreeView ptv = new pTreeView("~/");
        ptv.isWeb = false;
        ptv.PopulateTree(TreeView1);
    }
}

By default, the variable location will treat the path as a virtual path. If you want to specify a specific physical directory, you can specify the 8 character directory format as a location value but you need to specify the property “isWeb” as “false” and as shown above. The “TreeView1” is assumed to be a TreeView control placed onto the ASPX file. For testing purposes, you can put in your code behind the following code without placing a TreeView control in your ASPX file but will output the same.


TreeView TreeView1 = new TreeView();
string location;
pTreeView ptv = new pTreeView(location);
// the example below is valid without specifying the "isWeb" to false.
pTreeView ptv = new pTreeView("~/");
ptv.isWeb = false;
ptv.PopulateTree(TreeView1);

this.Form.Controls.Add(TreeView1);

Physical Drive TreeView DLL

The challenge for me is to bring the same functionality to a SourceSafe database which is despite having a directory like structure isn’t directory based at all when accessed programmatically. Furthermore, the DLL provided with Visual Source Safe 2005 isn’t a native .NET object but a COM interop one.

Luckily, using the same logic behind the previous DLL, I managed to create a DLL to populate a TreeView from a SourceSafe database. The constructor needs only 3 parameters namely the database location, username, and password.

Sample usage would be:


using ProjectTreeView;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string location, user, password;
        // Populate your own values

        ssTreeView stv = new ssTreeView(location, user, password);
        stv.BuildSourceSafeTree(TreeView1);

    }
}

Same with the code above, the code assumes that there’s a TreeView control instance in the ASPX file that has an ID of “TreeView1”.

Sourcesafe TreeView

For questions, feel free to add some comments. 🙂

Advertisements

Sourcesafe Automation Bug

As part of my continuing project in Sourcesafe Automation, I found a weird behavior of the Visual Studio Sourcesafe Interop DLL.

The following code is in Visual Basic 5 which basically connects to a Sourcesafe database and lists all the projects in the root folder of the database.


Dim vssdb As New VSSDatabase
 
vssdb.Open "<location to sourcesafe srcsafe.ini>", "<username>", "<password>"
 
Dim xitem As VSSItem
For Each xitem In vssdb.VSSItem(0).Items(False)
   Debug.Print (xitem.Name)
Next

Subsequently, the code equivalent in C# (.NET) , is something that I have blogged before. What I find unusual about the Sourcesafe Interop DLL are the following items:

Continue reading ‘Sourcesafe Automation Bug’

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


Blog Stats

  • 3,978 hits
October 2017
S M T W T F S
« Nov    
1234567
891011121314
15161718192021
22232425262728
293031