FileDialogPermissionAccess 枚举

指定所允许的通过文件对话框对文件访问权限的类型。

此枚举有一个 FlagsAttribute 属性,允许其成员值按位组合。

**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<FlagsAttribute> _
Public Enumeration FileDialogPermissionAccess
用法
Dim instance As FileDialogPermissionAccess
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[FlagsAttribute] 
public enum FileDialogPermissionAccess
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[FlagsAttribute] 
public enum class FileDialogPermissionAccess
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute FlagsAttribute() */ 
public enum FileDialogPermissionAccess
SerializableAttribute 
ComVisibleAttribute(true) 
FlagsAttribute 
public enum FileDialogPermissionAccess

成员

  成员名称 说明
None 没有通过文件对话框对文件的访问权限。 
Open 可以通过文件对话框打开文件。 
OpenSave 可以通过文件对话框打开并保存文件。 
Save 可以通过文件对话框保存文件。 

示例

Imports System
Imports System.Security
Imports System.Security.Permissions
Imports Microsoft.VisualBasic

Public Class FileDialogGenerator

    Private myFileDialog As FileDialogPermissionAccess() = _
        {FileDialogPermissionAccess.None, _
        FileDialogPermissionAccess.Open, _
        FileDialogPermissionAccess.OpenSave, _
        FileDialogPermissionAccess.Save}

    Private fileDialogIndex As Integer = 0

    Public Sub New()
        ResetIndex()
    End Sub 'New

    Public Sub ResetIndex()
        fileDialogIndex = 0
    End Sub 'ResetIndex

    ' Create a FileDialogPermission.
    Public Function CreateFileDialog(ByRef fileDialogPerm As FileDialogPermission, ByRef fileDialog As FileDialogPermissionAccess) As Boolean

        If fileDialogIndex >= myFileDialog.Length Then
            fileDialogPerm = New FileDialogPermission(PermissionState.None)
            fileDialog = FileDialogPermissionAccess.None
            Return False
        End If
        fileDialog = myFileDialog(fileDialogIndex)
        fileDialogIndex = fileDialogIndex + 1
        Try
            fileDialogPerm = New FileDialogPermission(fileDialog)
            Return True
        Catch e As Exception
            Console.WriteLine(("Cannot create FileDialogPermission: " & fileDialog & " " & e.ToString()))
            fileDialogPerm = New FileDialogPermission(PermissionState.None)
            fileDialog = FileDialogPermissionAccess.None
            Return True
        End Try
    End Function
End Class
using System;
using System.Security; 
using System.Security.Permissions; 

public  class FileDialogGenerator
{
    private FileDialogPermissionAccess[] myFileDialog = 
    {
        FileDialogPermissionAccess.None,
        FileDialogPermissionAccess.Open, 
        FileDialogPermissionAccess.OpenSave, 
        FileDialogPermissionAccess.Save};

    private int fileDialogIndex = 0;

    public FileDialogGenerator()
    {
        ResetIndex();
    }

    public void ResetIndex()
    {
        fileDialogIndex = 0;
    }
    // Create a FileDialogPermission.
    public bool CreateFileDialog(out FileDialogPermission fileDialogPerm, 
        out FileDialogPermissionAccess fileDialog)
    {

        if(fileDialogIndex >= myFileDialog.Length) 
        {
            fileDialogPerm = new FileDialogPermission(PermissionState.None);
            fileDialog=FileDialogPermissionAccess.None;
            return false;
        }
        fileDialog = myFileDialog[fileDialogIndex++];
        try
        {
            fileDialogPerm = new FileDialogPermission(fileDialog);
            return true;
        } 
        catch(Exception e)
        {
            Console.WriteLine("Cannot create FileDialogPermission: " + fileDialog +" "+e);
            fileDialogPerm = new FileDialogPermission(PermissionState.None);
            fileDialog=FileDialogPermissionAccess.None;
            return true;
        }
    }

}
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
public ref class FileDialogGenerator
{
private:
   array<FileDialogPermissionAccess>^myFileDialog;
   int fileDialogIndex;

public:
   FileDialogGenerator()
   {
      ResetIndex();
      array<FileDialogPermissionAccess>^ tempFileDialog = {FileDialogPermissionAccess::None,FileDialogPermissionAccess::Open,FileDialogPermissionAccess::OpenSave,FileDialogPermissionAccess::Save};
      myFileDialog = tempFileDialog;
   }

   void ResetIndex()
   {
      fileDialogIndex = 0;
   }


   // Create a FileDialogPermission.
   bool CreateFileDialog( [Out]interior_ptr<FileDialogPermission^> fileDialogPerm, [Out]FileDialogPermissionAccess * fileDialog )
   {
      if ( fileDialogIndex >= myFileDialog->Length )
      {
          *fileDialogPerm = gcnew FileDialogPermission( PermissionState::None );
          *fileDialog = FileDialogPermissionAccess::None;
         return false;
      }

       *fileDialog = myFileDialog[ fileDialogIndex++ ];
      try
      {
          *fileDialogPerm = gcnew FileDialogPermission(  *fileDialog );
         return true;
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Cannot create FileDialogPermission: {0} {1}",  *fileDialog, e );
          *fileDialogPerm = gcnew FileDialogPermission( PermissionState::None );
          *fileDialog = FileDialogPermissionAccess::None;
         return true;
      }

   }

};

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

System.Security.Permissions 命名空间
FileDialogPermission 类
FileDialogPermissionAttribute