c#打开对话框选择后输出文件路径文件名

<span style="font-family:KaiTi_GB2312;"> // 获取文件夹绝对路径    显示在 txtbox 控件里

System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();

if (folder.ShowDialog() == DialogResult.OK)
{
  textBox1.Text = folder.SelectedPath;              
}

// 获取文件和路径名 一起显示在 txtbox 控件里

<span style="font-size:12px;">OpenFileDialog dialog = new OpenFileDialog();
if (dialog .ShowDialog() == DialogResult.OK)
{
</span></span><pre name="code" class="csharp"><span style="font-family:KaiTi_GB2312;font-size:12px;">    textBox1.Text = dialog.FileName;                   </span>
} //如果只显示文件名OpenFileDialog dialog = new OpenFileDialog();if (dialog .ShowDialog() == DialogResult.OK){
<span style="font-family:KaiTi_GB2312;font-size:12px;">    textBox1.Text = dialog.SafeFileName;                   </span>
}
 
 

你可能感兴趣的:(c#打开对话框选择后输出文件路径文件名)