C# SaveFileDialog in specific folder

限于喜欢 提交于 2019-12-01 03:15:58

No it is not possible.

You can't directly set this as a Property on the SaveFileDialog. But you can try to do it by using the FileOk event to validate if the file is in that directory and otherwise cancel the event!

dialog.FileOk +=
    delegate (object sender, CancelEventArgs e)
    {
        if (dialog.FileName is in wrong directory)
        {
            e.Cancel = true;
        }
    };

As mentioned, the next best option is to build your own Dialog!

Some solutions that come to mind are:

Display an error after file selection

Not as nice as preventing the user in the first place, but it doesn't take a lot of code and is pretty straightforward.

Build your own file selection screen

Very painful to make look like anything that the user is accustomed to. Takes a lot of code.

What i can think of might be off-topic because it's not related as much with Programming and it might be difficult.

While you're application is being installed ,you should create a Specific User on Windows just for you're application.

Than you can start you're App. as that user using App. Manifest File.

After that you can give that Specific user permission's to write only at the root folder ,this how the OS will control that.

PS : I don't think if this solution will pay it self ,but it might work.

Salute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!