#727 – Getting a List of Files from the Clipboard

In Windows, if you do a Copy operation on a set of files, a list of filenames will get added to the clipboard.  You can get access to this list of files using the Clipboard.GetFileDropList method.

    public partial class MainWindow : Window, INotifyPropertyChanged
        public MainWindow()
            this.DataContext = this;

        public StringCollection FileList { get; set; }

        private void btnPasteFileList_Click(object sender, RoutedEventArgs e)
            if (Clipboard.ContainsFileDropList())
                FileList = Clipboard.GetFileDropList();

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string prop)
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(prop));

The XAML for this sample includes a ListBox that just binds to the FileList property.


        <ListBox ItemsSource="{Binding FileList}"/>
        <Button Grid.Column="1" Content="Paste File List"
                VerticalAlignment="Top" HorizontalAlignment="Left"
                Padding="10,5" Margin="10"