1. 程式人生 > >C# 打開文件夾窗口 存取文件路徑

C# 打開文件夾窗口 存取文件路徑

獲取文件夾路徑 分享 () indexof 後綴 subst led open directory

技術分享

OpenFileDialog file1 = new OpenFileDialog();
if (Properties.Settings.Default.path1!= "" && Properties.Settings.Default.path1 != null)
{
file1.InitialDirectory = Properties.Settings.Default.path1; //設置打開文件的路徑
}

file1.ShowDialog();//打開文件夾
if (file1.FileName!="" && file1.FileName != null)
{
m_FilePath = file1.FileName; //獲取文件路徑
string PathWJJ = (file1.FileName).Substring(0, (file1.FileName).Length-(((file1.FileName).Length - (file1.FileName).LastIndexOf(‘\\‘))));//獲取文件夾路徑
Properties.Settings.Default.path1 = PathWJJ;//保存文件夾路徑
Properties.Settings.Default.Save();
m_FileName = (file1.FileName).Substring((file1.FileName).LastIndexOf(‘\\‘) + 1, (file1.FileName).LastIndexOf(‘.‘) - (file1.FileName).LastIndexOf(‘\\‘) - 1);//獲取文件名,無後綴
this.textBox1.Text = m_FilePath;
}

C# 打開文件夾窗口 存取文件路徑