OpenFileDialog default path

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


        
8条回答
  •  情深已故
    2020-12-01 14:39

    For future me

    remember to do:

                try        
                {
                    result = dialog.ShowDialog(Window);
                }
                catch
                {
                    dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    result = dialog.ShowDialog(Window);
                }
    

    This helps in the situation when user opened file from location, that does not longer exists (ex. USB stick, mapped network drive) - ShowDialog throws exception if InitialDirectory is invalid.

提交回复
热议问题