WITH#: var saveDraftPath = Configura...">

Save file dialog - the path does not work

App.config:

<add key="SaveDraftPath" value="C:\Drafts\"/>

WITH#:

var saveDraftPath = ConfigurationManager.AppSettings["SaveDraftPath"]; 
var sfDialog = new SaveFileDialog();
sfDialog.InitialDirectory = saveDraftPath;
sfDialog.FileName = "FILE";

For some reason, this does not open the file browser in the way as planned, does anyone know why and how to fix it?

I tried this now, still not working:

var saveDraftPath = Path.GetFullPath(ConfigurationManager.AppSettings["SaveDraftPath"]);
MessageBox.Show("does directory exist : " + Directory.Exists(saveDraftPath));
var sfDialog = new SaveFileDialog();
sfDialog.InitialDirectory = saveDraftPath;
sfDialog.FileName = "FILE";

and Directory.Exists (saveDraftPath) returns true .. Hmmm ?!

Edit: The above code worked once for me. The code works for everyone who has so far answered. But it still does not work. Therefore, I suspect that the problem is in some kind of local / historical setting stopping him. Does anyone know why this could happen?

+3
source share
2 answers

Try the following:

var path = Path.GetFullPath(ConfigurationManager.AppSettings [ "SaveDraftPath" ])

Path

+1

( )

var saveDraftPath =
           ConfigurationManager.AppSettings["SaveDraftPath"];
        var sfDialog = new SaveFileDialog();
        sfDialog.InitialDirectory = saveDraftPath;
        sfDialog.FileName = "FILE";

        if (sfDialog.ShowDialog() == DialogResult.OK)
        {
            //do stuff
        }

. http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx

0

Source: https://habr.com/ru/post/1732932/


All Articles