How to save last folder in openFileDialog?

前端 未结 8 1943
刺人心
刺人心 2021-02-14 00:51

How do I make my application store the last path opened in openFileDialog and after new opening restore it?

OpenFileDialog openFileDialog1 = new Ope         


        
8条回答
  •  有刺的猬
    2021-02-14 01:28

    You can use the InitialDirectory property : http://msdn.microsoft.com/fr-fr/library/system.windows.forms.filedialog.initialdirectory.aspx

    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    openFileDialog1.InitialDirectory = previousPath;
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        previousPath = Path.GetDirectoryName(openFileDialog1.FileName);
        acc_path = openFileDialog1.FileName;
        Settings.Default.acc_path = acc_path;
    
        foreach (string s in File.ReadAllLines(openFileDialog1.FileName))
        {
            accs.Enqueue(s);
        }
        label2.Text = accs.Count.ToString();
    }
    

提交回复
热议问题