This documentation is archived and is not being maintained.

IVSSItem.Branch Method 

Visual Studio 2005

Branches a file that has been shared between one or more projects.

Namespace: Microsoft.VisualStudio.SourceSafe.Interop
Assembly: Microsoft.VisualStudio.SourceSafe.Interop (in microsoft.visualstudio.sourcesafe.interop.dll)

VSSItem Branch (
	[OptionalAttribute] [InAttribute] string Comment,
	[OptionalAttribute] [InAttribute] int iFlags
VSSItem Branch (
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String Comment, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int iFlags
function Branch (
	Comment : String, 
	iFlags : int
) : VSSItem



Optional. The default value is 0. For more information, see VSSFlags.


Optional. A string containing a comment. The default is an empty string.

Return Value

A reference of the IVSSItem type to an object that represents a newly branched file.


HRESULT Branch([in, defaultvalue(0)] BSTR Comment, [in, defaultvalue(0)] long iFlags, [out, retval] IVSSItem **ppIItem);

The Branch method applies to file objects only. If you attempt to branch a file that is not shared or branch a project object, a run-time error is generated.

The following example demonstrates how to use the Branch method to branch a file that has been shared by two projects. To run this example:

  • Create two folders, $/A and $/B.

    $/A folder must contain a file named a.txt.


using System;
using Microsoft.VisualStudio.SourceSafe.Interop;

public class IVSSTest
    public static void Main()
        // Create a VSSDatabase object.
        IVSSDatabase vssDatabase = new VSSDatabase();

        // Open a VSS database using network name 
        // for automatic user login.
                         Environment.UserName, ""); 

        // Get IVSSItem references to the project and the file objects.
        IVSSItem vssFolder = vssDatabase.get_VSSItem("$/B", false);
        VSSItem vssFile1 = vssDatabase.get_VSSItem("$/A/a.txt", false);

        // Share a file between two folders.
        vssFolder.Share(vssFile1, "Comment for share", 0);

        IVSSItem vssFile2 = vssDatabase.get_VSSItem("$/B/a.txt", false);
        // Break the shared link between folders $/A and $/B on file a.txt.
        vssFile2.Branch("Branch comment", 0);

        // Destroy file a.txt in folder $/B:

    private static void DisplayLinks(IVSSItem vssFile)
        Console.Write("\n{0} contains links:", vssFile.Spec);
        foreach(IVSSItem vssItem in vssFile.Links)
            Console.Write("  {0}", vssItem.Spec);


$/A/a.txt contains links: $/A/a.txt

$/A/a.txt contains links: $/B/a.txt $/A/a.txt

$/A/a.txt contains links: $/A/a.txt