OpenFileDialog取绝对路径 OpenFileDialog取绝对路径,比如我的文件在C盘。我选中之后在txt框里现实的路径就是C盘的路径,现在现实的时候项目所在的位置。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 OpenFileDialog有很多属性可以设置,请参考MSDN OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = @"C:\"; ofd.ShowDialog(); private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog()==DialogResult.OK) { string str = ofd.FileName; str=str.Remove(str.LastIndexOf(@"\")+1); textBox1.Text = str; } } OpenFileDialog.FileName显示的就是文件的绝对路径从硬盘根目录一直选中的文件名 OpenFileDialog openDlg = new OpenFileDialog();openDlg.FileName;//绝对路径 FolderBrowserDialognew DirectoryInfo(cdlg.FileName).Root.FullName Directory.GetDirectoryRoot(cdlg.FileName) 正则问题 C#一个控件事件调用另一个控件事件的问题 oledbdatareader C#都搞函数重载了,为什么还要弄委托呢? 新型Pad点菜系统 Xml的方法 用什么函数可以一次性清空清空datagrid中所有行 刚学C#不久,这样实现杨辉三角可以么?? 用.NET 怎么去读exchang Server里面的数据,比如EXCEL 文件? 朋友做毕业设计,要用c#做一个系统,麻烦推荐一本好书!! TXT转PDF如何实现? 请问bitmap怎么赋值?
请参考MSDN
ofd.InitialDirectory = @"C:\";
ofd.ShowDialog();
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog()==DialogResult.OK)
{
string str = ofd.FileName;
str=str.Remove(str.LastIndexOf(@"\")+1);
textBox1.Text = str;
}
}
从硬盘根目录一直选中的文件名
openDlg.FileName;//绝对路径