我想搜索一个位于特定文件夹中的文件,当我点击一个按钮时,它将在Windows资源管理器中打开..
private void button3_Click(object sender, EventArgs e)
{
DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo("H:\\studio\\");
FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles("*" + txt_mobile .Text + "*.*");
foreach (FileInfo foundFile in filesInDir)
{
string fullName = foundFile.FullName;
using (var fileStream = new FileStream(fullName , FileMode.Open, FileAccess.Read))
{
}
}
}
我无法打开包含文件夹的文件,该文件夹在“fullName”字符串中指定。
答案 0 :(得分:0)
我认为这会为你做到这一点
FileDialog.InitialDirectory会帮助你。由于initial directory
显示在文件对话框中。 FileDialog.FileName可以初始化为预设的文件名。
OpenFileDialog openFileDialog1 = new OpenFileDialog();
//Take out only the directory path instead of full path.
openFileDialog1.InitialDirectory = TextBoxPath.Text;
//Take out only the file name instead of full path.
openFileDialog1.FileName = TextBoxPath.Text;
希望这有帮助