質問

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