OpenFileDialog default path

前端 未结 8 1389
甜味超标
甜味超标 2020-12-01 14:13
using (var openFileDialog1 = new OpenFileDialog())
        {
            openFileDialog1.Reset();
            if (!string.IsNullOrEmpty(ExcelFilePath))
            {         


        
相关标签:
8条回答
  • 2020-12-01 14:46

    It seems like all you need to do is the following:

    string path; // this is the path that you are checking.
    if(Directory.Exists(path)) {
        openFileDialog1.InitialDirectory = path;
    } else {
        openFileDialog1.InitialDirectory = @"C:\";
    } 
    

    That is unless I'm missing something.

    0 讨论(0)
  • 2020-12-01 14:52

    I don't think there is anything built in for that. Just check before you open the dialog:

    if (!Directory.Exists(initialDirectory))
    {
        openFileDialog1.InitialDirectory = @"C:\";
    }
    
    0 讨论(0)
提交回复
热议问题