IVSSItem.Share Method 

Creates a share link between two projects for a file or a project.

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

Syntax

'Declaration
Sub Share ( _
    <InAttribute> pIItem As VSSItem, _
    <InAttribute> <OptionalAttribute> Optional Comment As String = "", _
    <InAttribute> <OptionalAttribute> Optional iFlags As Integer = 0 _
)
'Usage
Dim instance As IVSSItem
Dim pIItem As VSSItem
Dim Comment As String
Dim iFlags As Integer

instance.Share(pIItem, Comment, iFlags)
void Share (
    [InAttribute] VSSItem pIItem,
    [OptionalAttribute] [InAttribute] string Comment,
    [OptionalAttribute] [InAttribute] int iFlags
)
void Share (
    [InAttribute] VSSItem^ pIItem, 
    [InAttribute] [OptionalAttribute] String^ Comment, 
    [InAttribute] [OptionalAttribute] int iFlags
)
void Share (
    /** @attribute InAttribute() */ VSSItem pIItem, 
    /** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String Comment, 
    /** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int iFlags
)
function Share (
    pIItem : VSSItem, 
    Comment : String, 
    iFlags : int
)

Parameters

  • pIItem
    Represents a file or a project to be shared.
  • 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.

Remarks

[IDL]

HRESULT Share ([in]IVSSItem *pIItem, [in,defaultvalue(0)]BSTR Comment, [in,defaultvalue(0)]long iFlags);

When files or folders are shared, changes to these files or folders are reflected in all projects that share them. Every file and folder has at least one link — to itself.

When sharing a project, all files within the project are shared (the projects are not shared). If you use the flag VSSFLAG_RECURSYES, all files in subprojects are shared as well.

If you attempt to share a file into a project that already contains a file with the same name, or if you try to recursively share a project to one of its descendants, a run-time error is generated.

Example

The following example demonstrates how to use the Share method to share a file between two projects. To run this example:

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

    $/A folder must contain a.txt file.

[C#]

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.
        vssDatabase.Open(@"C:\VSSTestDB\srcsafe.ini", 
                         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);

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

        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);
        DisplayLinks(vssFile1);

        // Destroy file a.txt in folder $/B:
        vssFile2.Destroy();
    }

    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);
    }
}

Output:

$/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

See Also

Reference

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