我在以下行收到一条错误消息:“路径不是合法形式”:
fileSystemWatcher2.EnableRaisingEvents = true;
这是我的代码:
private void Browse_file_Click(object sender, EventArgs e)
{
DialogResult resDialog = openFileDialog1.ShowDialog();
if (resDialog == DialogResult.OK)
{
FileBrowseBox.Text = openFileDialog1.FileName;
}
fileSystemWatcher1.EnableRaisingEvents = false; // Stop watching
fileSystemWatcher1.IncludeSubdirectories = true;
fileSystemWatcher1.Path = Path.GetDirectoryName(FileBrowseBox.Text); // Text of textBox2 = Path of fileSystemWatcher2
fileSystemWatcher1.EnableRaisingEvents = true; // Begin watching
}
private void Browse_destination_Click(object sender, EventArgs e)
{
if (dlgOpenDir.ShowDialog() == DialogResult.OK)
{
fileSystemWatcher2.EnableRaisingEvents = false; // Stop watching
fileSystemWatcher2.IncludeSubdirectories = true;
DestinationBox.Text = dlgOpenDir.SelectedPath;
fileSystemWatcher2.Path = DestinationBox.Text;
fileSystemWatcher2.EnableRaisingEvents = true; // Begin watching
}
}
这是 DestinationBox.Text
我需要它来向它传输文件,但我也想在其中使用 filewatch 会发生什么我用 FileSystemWatcher2 解决了它,但在 FileSystemWatcher1 仍然给我一个错误