title: Setting PathAnnotation on SSIS path from code
body: <p>I have been trying lately to create SSIS packages from .NET code rather than using drag and drop in Visual Studio. As part of the package documentation, I would like to be able to annotate data flow paths.</p>
  
  <p>The code below - copied from <a href="http://msdn.microsoft.com/en-us/library/ms136086.aspx" rel="nofollow">MSDN</a> - establishes a path between two SSIS data flow components. By adding</p>
  
  <pre><code>    path.Name = "My name";
      new Application().SaveToSqlServer(package, null, "localhost", "myUser", "myPassword");
  </code></pre>
  
  <p>I can set the name of the path to whatever I like and then save the package in my local SQL Server. When I open the package in Visual Studio 2008, however, the name of the path can only be seen under path properties.</p>
  
  <p>In Visual Studio, there is another path property, PathAnnotation, with the value AsNeeded and additional possibilities SourceName, PathName, Never. Changing the value to PathName gives me what I want: The path name appears next to the path in the data flow tab in Visual Studio.</p>
  
  <p>My question is: Is it possible to set the value of the PathAnnotation property from code?</p>
  
  <pre><code>using System;
  using Microsoft.SqlServer.Dts.Runtime;
  using Microsoft.SqlServer.Dts.Pipeline;
  using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
  
  namespace Microsoft.SqlServer.Dts.Samples
  {
    class Program
    {
      static void Main(string[] args)
      {
        Package package = new Package();
        Executable e = package.Executables.Add("STOCK:PipelineTask");
        TaskHost thMainPipe = e as TaskHost;
        MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;
  
        // Create the source component.  
        IDTSComponentMetaData100 source =
          dataFlowTask.ComponentMetaDataCollection.New();
        source.ComponentClassID = "DTSAdapter.OleDbSource";
        CManagedComponentWrapper srcDesignTime = source.Instantiate();
        srcDesignTime.ProvideComponentProperties();
  
        // Create the destination component.
        IDTSComponentMetaData100 destination =
          dataFlowTask.ComponentMetaDataCollection.New();
        destination.ComponentClassID = "DTSAdapter.OleDbDestination";
        CManagedComponentWrapper destDesignTime = destination.Instantiate();
        destDesignTime.ProvideComponentProperties();
  
        // Create the path.
        IDTSPath100 path = dataFlowTask.PathCollection.New();
        path.AttachPathAndPropagateNotifications(source.OutputCollection[0],
          destination.InputCollection[0]);
      }
    }
  </code></pre>