Hello. There was a problem opening the program file in Notepad.
string tmp = listBox1.SelectedItem.ToString(); tmp = tmp.Replace("\\", "\\\\"); Process.Start("C:\\Windows\\System32\\notepad.exe", tmp);
If you double-click on a line in the listbox, the notepad opens and the error "Syntax error in the file name, folder name or volume label." This is very strange, because I screen slashes and errors should not be ...
I tried to create a string, and write the path to the file in it (of course, escaping slashes, a string like "C: \ file.txt "), the file opened remarkably in notepad and this fact put me at a dead end ... i do wrong i don't understand ...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO ; using System.Diagnostics; namespace FindFile { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { progressBar1.Step = 0; progressBar1.PerformStep(); string TmpFile = ""; int NumberFiles = 0; List<string> FileOfName = new List<string>(); System.String path = PathFile.Text; try { foreach (var file in Directory.GetFiles(path, SelectType.SelectedItem.ToString(), SearchOption.AllDirectories)) { StreamReader FindFile = new StreamReader(file); string str = ""; while (!FindFile.EndOfStream) { str = FindFile.ReadLine(); if ((str.IndexOf(Substring.Text) > -1) && !TmpFile.Equals(file)) { FileOfName.Add(file); TmpFile = file; NumberFiles++; } } } if (NumberFiles != 0) { int StepProgressBar = NumberFiles / 100; progressBar1.Step = StepProgressBar; foreach (string s in FileOfName) { listBox1.Items.Add(s + "\n"); progressBar1.PerformStep(); } } else { progressBar1.Step = 100; progressBar1.PerformStep(); MessageBox.Show("По указанному пути введенная вами строка не найдена"); } } catch (Exception error) { MessageBox.Show(error.ToString()); } } private void listBox1_DoubleClick(object sender, EventArgs e) { string tmp = listBox1.SelectedItem.ToString(); //tmp = tmp.Replace("\\", "\\\\"); MessageBox.Show(tmp); Process.Start("C:\\Windows\\System32\\notepad.exe", tmp); } } }