문제

I am trying to use the openFileDialog, it was working up until this morning when I made what I thought was a simple change....

I changed the Filter and Initial Directory properties from hardcoded strings to application settings and this is where the error comes in. From what I can tell everything should be fine... Ill post the new and old code....

NEW CODE

    private void btnOpenFile_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog ofDialog = new OpenFileDialog();
        ofDialog.Filter = Properties.Settings.Default.openFileFilter;
        ofDialog.FilterIndex = 3;
        ofDialog.Multiselect = false;
        ofDialog.InitialDirectory = Properties.Settings.Default.openFileInitialDirectory;

        bool? fileSelected = ofDialog.ShowDialog();

        if(fileSelected == true)
        {
            selectedFileTxtBx.Text = ofDialog.FileName;
        }

Application Settings

 Properties.Settings.Default.openFileFilter; = Exe (.exe)|*.exe|MSI (.msi)|*.msi| All (*.*)|*.*
 Properties.Settings.Default.openFileInitialDirectory; = \\\\UNC\\PATH

Old Code

    private void btnOpenFile_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog ofDialog = new OpenFileDialog();
        ofDialog.Filter = "Exe (.exe)|*.exe|MSI (.msi)|*.msi| All (*.*)|*.*";
        ofDialog.FilterIndex = 3;
        ofDialog.Multiselect = false;
        ofDialog.InitialDirectory = "\\\\UNC\\PATH";

        bool? fileSelected = ofDialog.ShowDialog();

        if(fileSelected == true)
        {
            selectedFileTxtBx.Text = ofDialog.FileName;
        }
    }
도움이 되었습니까?

해결책

If memory serves correctly, Properties.Settings.Default.openFileInitialDirectory should actually just be set to \\UNC\PATH, as the string will already be escaped.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top