Share via


IVSSItem.Label Method 

Applies a label to a file or a project.

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

Syntax

'Declaration
Sub Label ( _
    <InAttribute> Label As String, _
    <InAttribute> <OptionalAttribute> Optional Comment As String = "" _
)
'Usage
Dim instance As IVSSItem
Dim Label As String
Dim Comment As String

instance.Label(Label, Comment)
void Label (
    [InAttribute] string Label,
    [OptionalAttribute] [InAttribute] string Comment
)
void Label (
    [InAttribute] String^ Label, 
    [InAttribute] [OptionalAttribute] String^ Comment
)
void Label (
    /** @attribute InAttribute() */ String Label, 
    /** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String Comment
)
function Label (
    Label : String, 
    Comment : String
)

Parameters

  • Label
    A string containing the label applied to a file or a project.
  • Comment
    Optional. A string containing a comment. The default is an empty string.

Remarks

[IDL]

HRESULT Label ([in]BSTR Label, [in,defaultvalue(0)]BSTR Comment);

When you use the Label method, you create a new version in the history of the file or project. However, the file or project remains unchanged.

A label that is applied to a project is inherited by all subprojects and files within the project.

Note

If you assign a label to a version that already has a label, you overwrite the label.

Example

The following example demonstrates how to use the Label method to label a file. In this example a new label, Alpha, is added and then removed from the test.txt file.

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

public class IVSSTest
{
    public static void Main()
    {
        string testFile = "$/A/test.txt";

        // Create a VSSDatabase object.
        IVSSDatabase vssDatabase = new VSSDatabase();

        // Open a VSS database using network name 
        // for automatic user login.
        vssDatabase.Open(@"C:\VSSTestDB\srcsafe.ini", 
                         Environment.UserName, ""); 

        // Display all versions of the file.
        VSSItem vssFile = vssDatabase.get_VSSItem(testFile, false);
        DisplayVersions(vssFile);
        
        // Add a label.
        vssFile.Label("Alpha", "Labeling Alpha");
        DisplayVersions(vssFile);
        
        // Remove a label.
        vssFile = vssFile.get_Version("Alpha"); 
        vssFile.Label("", "");
        DisplayVersions(vssFile);
    }

    private static void DisplayVersions(VSSItem vssFile)
    {
        Console.WriteLine("-------------");
        Console.WriteLine("Ver  Label");
        Console.WriteLine("-------------");
        // Use default (0) setting in get_Versions
        foreach(VSSVersion vssVersion in vssFile.get_Versions(0))    
            Console.WriteLine("{0,-5}{1}", vssVersion.VersionNumber, 
                              vssVersion.Label);
        Console.WriteLine("\n");
    }
}

Output:

-------------

Ver Label

-------------

3

2

1

-------------

Ver Label

-------------

4 Alpha

3

2

1

-------------

Ver Label

-------------

3

2

1

See Also

Reference

IVSSItem Interface
IVSSItem Members
Microsoft.VisualStudio.SourceSafe.Interop Namespace