Search code examples
c#wpfsavefiledialog

How to avoid permission validation in SaveFileDialog?


When using SaveFileDialog and selecting to save in a folder in which the user has no permission to write to, a warning dialog appears and prevents the user from continuing.

var sfd = new SaveFileDialog
{
    FileName = name,
    InitialDirectory = initial,
    Filter = "Text (.txt)|*.txt",
    DefaultExt = ".txt"
};

var result = sfd.ShowDialog();

Validation

Is there any way to prevent this validation, while continuing using the SaveFileDialog, without resorting to elevating the process?


Solution

  • Short answer: No.

    There is no setting or property that you can use to bypass the security mechanism of the operating system.

    Set the InitialDirectory property to a folder that you know that users have write access or endure the warning.