[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Find, open, and replace text in files in C#

[Find, open, and replace text in files in C#]

The example Find files and replace text in them in C# shows how you can find and replace text in files. This example modifies that one to let you open the files you find by double clicking on them in the program's list box. For example, you can search for a file and then double-click on it to open it in the system's default application for that file. That lets you search for files containing a string and then open some of them to examine them or modify them manually.

The following code shows how the programs opens the selected files when you double-click on the list of files.

// Open the double-clicked files with // the system's default application. private void lstFiles_DoubleClick(object sender, EventArgs e) { foreach (string file in lstFiles.SelectedItems) { System.Diagnostics.Process.Start(file); } }

Usually you will probably double-click a single file but the code loops through the ListBox's SelectedItems collection to open all of the selected files (in case you shift-double-click or something).

For each selected file, the program calls Process.Start to "run" the file. That makes the system open it using the appropriate application.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.