SearchOption Enumeration
Silverlight
Specifies whether to search the current directory, or the current directory and all subdirectories.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
The following code example lists all of the directories and files that begin with the letter "c" in the "My Documents" folder. In this example, the SearchOption is used to specify not to search all subdirectories.
using System; using System.IO; using System.Collections.Generic; class Example { public static void Demo(System.Windows.Controls.TextBlock outputBlock) { string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string searchPattern = "c*"; IEnumerable<string> directories = Directory.EnumerateDirectories(path, searchPattern, SearchOption.TopDirectoryOnly); IEnumerable<string> files = Directory.EnumerateFiles(path, searchPattern, SearchOption.TopDirectoryOnly); outputBlock.Text += String.Format( "Directories that begin with the letter \"c\" in {0}", path) + "\n"; foreach (string dir in directories) { outputBlock.Text += dir + "\n"; } outputBlock.Text += "\n"; outputBlock.Text += String.Format( "Files that begin with the letter \"c\" in {0}", path) + "\n"; foreach (string file in files) { outputBlock.Text += file + "\n"; } } }
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Community Additions
ADD
Show: