Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

IVSSItem.Add Method 

Visual Studio 2005

Adds a file to a project.

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

VSSItem Add (
	[InAttribute] string Local,
	[OptionalAttribute] [InAttribute] string Comment,
	[OptionalAttribute] [InAttribute] 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.

[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.

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

Community Additions

ADD
Show:
© 2015 Microsoft