开发者

Save file dialog - path not working

App.config:

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

C#:

var saveDraftPath = Configu开发者_如何学JAVArationManager.AppSettings["SaveDraftPath"]; 
var sfDialog = new SaveFileDialog();
sfDialog.InitialDirectory = saveDraftPath;
sfDialog.FileName = "FILE";

For some reason this doesn't open the filebrowser in the path like planned, any one know why or how to fix?

I've tried this now, still doesn't work:

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 has worked once for me. The code works for everyone who has so far answered. But it is still not working. So I suspect the problem is some sort of local/history setting stopping it. Does anyone know why this might happen?


Try this:

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

Have a look at Path Class as well, has got several helpful methods


this worked for me (getting the correct path from the config)

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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜