0
var ext = new List<string> { ".jpg", ".gif", ".png" };
var myFiles = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories)
     .Where(s => ext.Any(e => s.EndsWith(e)));
CopyFilesToClipBoard()

And the method CopyFilesToClipBoard()

public static string[] CopyFilesToClipBoard(List<string> file_list)
{
    foreach (string file_name in Directory.GetFiles(Application.StartupPath))
        file_list.Add(file_name);
    Clipboard.Clear();
    Clipboard.SetData(DataFormats.FileDrop, file_list.ToArray());
    string[] file_names = (string[])
    Clipboard.GetData(DataFormats.FileDrop);
    return file_names;
}

The problem is that CopyFilesToClipBoard should get List but var myFiles is IEnumerable

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Shmuel Naukarkar
  • 233
  • 1
  • 2
  • 12
  • 5
    Your `CopyFilesToClipboard` method seems to have two purposes - it adds the files in the startup path to the list, *and* it copies things to the clipboard. I'd strongly recommend that you separate the two. – Jon Skeet Mar 05 '16 at 20:29

1 Answers1

4

You could just call the ToList method:

CopyFilesToClipBoard(myFiles.ToList());
Christos
  • 53,228
  • 8
  • 76
  • 108