This document is archived and information here might be outdated.  Recommended version.


List Files to Clipboard Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

List Files to Clipboard Snippet

Obtain a listing of files for a specified directory and place them in the Windows Clipboard.

[C#]
///<summary>Obtain a listing of files for a specified directory and place them in the Windows Clipboard.</summary>
/// 
///<param name="directory">A System.String that is the directory for which you want to list files in the Windows Clipboard. Ex: "C:\temp"</param>
/// 
///<remarks></remarks>
public void ListFilesToClipboard(System.String directory)
{

  System.IO.DirectoryInfo directoryInfo=new System.IO.DirectoryInfo(directory);
  System.Text.StringBuilder stringBuilder=new System.Text.StringBuilder(2000);

  if (directoryInfo != null)
  {

        System.IO.FileInfo[] fileInfo=directoryInfo.GetFiles();
        System.Int32 i=0;

        System.Int32 tempFor1=fileInfo.GetUpperBound(0);
        for (i=0; i <= tempFor1; i++)
        {

          stringBuilder.Append(fileInfo[i].Name + System.Environment.NewLine);

        }

        System.Windows.Forms.Clipboard.SetDataObject(stringBuilder.ToString());

  }

}
[Visual Basic .NET]
'''<summary>Obtain a listing of files for a specified directory and place them in the Windows Clipboard.</summary>
''' 
'''<param name="directory">A System.String that is the directory for which you want to list files in the Windows Clipboard. Ex: "C:\temp"</param>
''' 
'''<remarks></remarks>
Public Sub ListFilesToClipboard(ByVal directory As System.String)

  Dim directoryInfo As System.IO.DirectoryInfo=New System.IO.DirectoryInfo(directory)
  Dim stringBuilder As System.Text.StringBuilder=New System.Text.StringBuilder(2000)

  If Not (directoryInfo Is Nothing) Then

    Dim fileInfo As System.IO.FileInfo()=directoryInfo.GetFiles
    Dim i As System.Int32

    For i=0 To fileInfo.GetUpperBound(0)

      stringBuilder.Append(fileInfo(i).Name + System.Environment.NewLine)

    Next i

    System.Windows.Forms.Clipboard.SetDataObject(stringBuilder.ToString)

  End If

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • System
  • System.Windows.Forms