Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

FileDialogPermissionAccess Enumeration

Specifies the type of access to files allowed through the File dialog boxes.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Security.Permissions
Assembly:  mscorlib (in mscorlib.dll)

public enum FileDialogPermissionAccess

Member nameDescription
NoneNo access to files through the File dialog boxes.
OpenAbility to open files through the File dialog boxes.
SaveAbility to save files through the File dialog boxes.
OpenSaveAbility to open and save files through the File dialog boxes.

The following code example demonstrates the declarative and imperative forms of the FileDialogPermission class by using the FileDialogPermissionAccess enumeration to specify the type of access that is to be allowed through the File dialog boxes.

using System;
using System.Security;
using System.Security.Permissions;
using System.Windows.Forms;
using System.IO;

// Add the declarative FileDialogPermissionAttribute to request minimum 
// permissions for the code in this class to run.
public class DialogPermissions
    private Stream fileStream;

    public static void Main()
        DialogPermissions dialogAccess = new DialogPermissions();
        Console.WriteLine("Opened file " + dialogAccess.OpenFile());

        // Deny permission to use of the Open dialog box.
        FileDialogPermission dialogPermission = 
            new FileDialogPermission(FileDialogPermissionAccess.Open);




    // Display open dialog box, store the file stream of the specified file 
    // in the fileStream member variable. 
    private string OpenFile()
        string fileName = null;

        OpenFileDialog openDialogBox = new OpenFileDialog();
        openDialogBox.InitialDirectory = "c:\\";
        openDialogBox.Filter = "txt files (*.txt)|*.txt";
        openDialogBox.RestoreDirectory = true;
            // If user selects OK, store file name and stream. 
            if(openDialogBox.ShowDialog() == DialogResult.OK)
                fileName = openDialogBox.FileName;
                fileStream = openDialogBox.OpenFile();
        catch (Exception ex)


        // Return specified file name. 
        return fileName;

    // Close the file stream. 
    private void CloseStream()
        if (fileStream != null)
// This sample produces the following output: 
// Opened file C:\testfile.txt 
// Request for the permission of type  
// System.Security.Permissions.FileDialogPermission, mscorlib,  
// Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089  
// failed. 
// This sample completed successfully; press Exit to continue.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

© 2015 Microsoft