Share via


IVSSItem.Add Method 

Adds a file to a project.

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

Syntax

'Declaration
Function Add ( _
    <InAttribute> Local As String, _
    <InAttribute> <OptionalAttribute> Optional Comment As String = "", _
    <InAttribute> <OptionalAttribute> Optional iFlags As Integer = 0 _
) As VSSItem
'Usage
Dim instance As IVSSItem
Dim Local As String
Dim Comment As String
Dim iFlags As Integer
Dim returnValue As VSSItem

returnValue = instance.Add(Local, Comment, iFlags)
VSSItem Add (
    [InAttribute] string Local,
    [OptionalAttribute] [InAttribute] string Comment,
    [OptionalAttribute] [InAttribute] int iFlags
)
VSSItem^ Add (
    [InAttribute] String^ Local, 
    [InAttribute] [OptionalAttribute] String^ Comment, 
    [InAttribute] [OptionalAttribute] int iFlags
)
VSSItem Add (
    /** @attribute InAttribute() */ String Local, 
    /** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String Comment, 
    /** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int iFlags
)
function Add (
    Local : String, 
    Comment : String, 
    iFlags : int
) : VSSItem

Parameters

  • Local
    A string representing a fully qualified local path of a file to be added to a project.
  • Comment
    Optional. A string containing a comment. The default is an empty string.
  • iFlags
    Optional. The default value is 0.

    For more information, see VSSFlags.

Return Value

A reference of the IVSSItem type to an object that represents a file added to a project.

Remarks

[IDL]

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

The Add method applies to project objects only. If you attempt to call the Add method against a file object or add a file that already exists in the project, a run-time error is generated.

Example

The following example demonstrates how to use the Add method to add a new file to the project.

[C#]

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

public class IVSSTest
{
    public static void Main()
    {
        string testFolder = "$/TestFolder";
        string testFile = @"C:\VSSTestWF\TestFolder\fileAdd.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, ""); 

        // Create a VSSItem specifying the desired folder.
        VSSItem vssFolder = vssDatabase.get_VSSItem(testFolder, false);

        // Display folder contents prior to adding a file.
        DisplayFolderContent(vssFolder);

        // Add a file to the project.
        VSSItem vssTestFile = vssFolder.Add(testFile, "Adding a new file", 0);

        // Display folder contents after adding a file.
        DisplayFolderContent(vssFolder);

        // Destroy the new file.
        vssTestFile.Destroy();

        // Display folder contents after destroying the new file.
        DisplayFolderContent(vssFolder);
    }

    private static void DisplayFolderContent(IVSSItem vssFolder)
    {
        Console.Write("\n{0} contains:", vssFolder.Spec);
        foreach(VSSItem vssItem in vssFolder.get_Items(false))
            Console.Write(" {0}", vssItem.Name);
    }
}

Output:

$/TestFolder contains: file1.txt file2.txt

$/TestFolder contains: fileAdd.txt file1.txt file2.txt

$/TestFolder contains: file1.txt file2.txt

See Also

Reference

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