문제

Here's what I have so far:

private void ChangeLotFilePath()
    {
        OpenFileDialog Dialog = new OpenFileDialog();
        Dialog.Filter = "XML files (*.xml)|*.xml";
        Dialog.ShowDialog();

        using (DDataContext context = new DDataContext())
        {
            SystemConfiguration config = context.SysConfig.First();

            if (config != null)
            {
                Dialog.InitialDirectory = config.LotLoadingDirectory;

            }
        }


        if (!String.IsNullOrEmpty(Dialog.FileName))
        {
            LotFileCreationDirectory = Dialog.FileName;
            DeSerializationXML(Dialog.FileName);
        }

    }

For some reason, when I set LotFileCreationDirectory = Dialog.InitialDirectory, the directory in openfiledialog does not default to anything or I get a access denied error.

I'm not sure what I'm doing wrong. I'm just trying to grab the directory path configured by the administrator from the database and setting that directory to default when openfiledialog opens. Then the user can select an xml file from that directory.

Here's my property:

private const string LOT_FILE_CREATION_DIRECTORY = "LotFileCreationDirectory";
    public string LotFileCreationDirectory
    {
        get
        {
            return LotFileCreationDirectory;
        }
        set
        {
            LotFileCreationDirectory = value;
            RaisePropertyChanged(LOT_FILE_CREATION_DIRECTORY);
        }
    }
도움이 되었습니까?

해결책

you are showing the dialog:

OpenFileDialog Dialog = new OpenFileDialog();
Dialog.Filter = "XML files (*.xml)|*.xml";
Dialog.ShowDialog();

before you are setting it's InitialDirectory:

Dialog.InitialDirectory = config.LotLoadingDirectory;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top