Customizing OpenFileDialog

前端 未结 3 702
长发绾君心
长发绾君心 2020-11-30 09:34

I am working on winforms application in C#. What I want to achieve is to get a file from user for which I am using the following code:

OpenFileDialog dlg =          


        
3条回答
  •  鱼传尺愫
    2020-11-30 09:39

    Try this code:

    private void Browse_Click(object sender, EventArgs e)
    {
        var fdlg = new OpenFileDialog();
        fdlg.Title = "Open a file";
        fdlg.InitialDirectory = "c:/";
        fdlg.Filter = "all files(*.*)|*.*|all files(*.)|*.*";
        fdlg.FilterIndex = 2;
        fdlg.RestoreDirectory = true;
        if (fdlg.ShowDialog() == DialogResult.OK)
        {
            filetxt.Text = fdlg.FileName;
        }
    }
    

提交回复
热议问题