OpenFileDialog default path

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


        
8条回答
  •  鱼传尺愫
    2020-12-01 14:35

    In case you're using file name stored in some string, it's better to use Path to cut the file name (on my W10 the open dialog doesn't open in initial directory, if I supply just file name):

        if (!System.IO.Directory.Exists(filename))
        {
            openDlg.InitialDirectory =
                System.IO.Path.GetDirectoryName(filename);
        }
    

提交回复
热议问题