Freigeben über


FileDialogPermission-Klasse

Steuert die Möglichkeit des Zugriffs auf Dateien oder Ordner über ein Dateidialogfeld. Diese Klasse kann nicht vererbt werden.

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

Syntax

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class FileDialogPermission
    Inherits CodeAccessPermission
    Implements IUnrestrictedPermission
'Usage
Dim instance As FileDialogPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class FileDialogPermission : CodeAccessPermission, IUnrestrictedPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class FileDialogPermission sealed : public CodeAccessPermission, IUnrestrictedPermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class FileDialogPermission extends CodeAccessPermission implements IUnrestrictedPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class FileDialogPermission extends CodeAccessPermission implements IUnrestrictedPermission

Hinweise

Mit dieser Berechtigung wird i. d. R. ein eingeschränkter Zugriff auf vom Benutzer angegebene Dateien gewährt, wenn FileIOPermission nicht erteilt wird.

Beispiel

Im folgenden Codebeispiel wird das Verhalten der Methoden der FileDialogPermission-Klasse veranschaulicht. Dieses Beispiel soll lediglich die Ergebnisse der Methoden veranschaulichen, nicht deren typische Verwendung. Ein Beispiel, in dem die Verwendung der FileDialogPermission-Klasse zum Fordern der Berechtigung für einen bestimmten FileDialogPermissionAccess-Enumerationswert veranschaulicht wird, finden Sie unter dem FileDialogPermission(FileDialogPermissionAccess)-Konstruktor.

Imports System
Imports System.Security
Imports System.Security.Permissions



<assembly: CLSCompliant(True)>
 

Public Class FileDialogPermissionDemo
    Private fileDialogPerm1 As New FileDialogPermission(FileDialogPermissionAccess.Open)
    Private fileDialogPerm2 As New FileDialogPermission(FileDialogPermissionAccess.OpenSave)
    Private fileDialogPerm3 As New FileDialogPermission(PermissionState.None)
    
    ' IsSubsetOf determines whether the current permission is a subset of the
    ' specified permission.
    Private Function IsSubsetOfDemo() As Boolean 
        Dim returnValue As Boolean = True
        
        
        If fileDialogPerm1.IsSubsetOf(fileDialogPerm2) Then
            Console.WriteLine(fileDialogPerm1.Access.ToString() + " is a subset of " _
            + fileDialogPerm2.Access.ToString())
        Else
            Console.WriteLine(fileDialogPerm1.Access.ToString + " is not a subset of " + _
            fileDialogPerm2.Access.ToString())
        End If
        
        Return returnValue
    
    End Function 'IsSubsetOfDemo
    
    ' Union creates a new permission that is the union of the current permission and the
    ' specified permission.
    Private Function UnionDemo() As Boolean 
        Dim returnValue As Boolean = True
        
        fileDialogPerm3 = CType(fileDialogPerm1.Union(fileDialogPerm2), FileDialogPermission)
        
        If fileDialogPerm3 Is Nothing Then
            Console.WriteLine("The union of " + fileDialogPerm1.Access.ToString() + _
            " and " + fileDialogPerm2.Access.ToString() + " is null.")
        Else
            Console.WriteLine("The union of " + fileDialogPerm1.Access.ToString() + _
            " and " + fileDialogPerm2.Access.ToString() + " = " + _
            CType(fileDialogPerm3, FileDialogPermission).Access.ToString())
        End If
        
        Return returnValue
    
    End Function 'UnionDemo
     
    ' Intersect creates and returns a new permission that is the intersection of the current
    ' permission and the permission specified.
    Private Function IntersectDemo() As Boolean 
        Dim returnValue As Boolean = True
        
        fileDialogPerm3 = CType(fileDialogPerm1.Intersect(fileDialogPerm2), FileDialogPermission)
        If Not (fileDialogPerm3 Is Nothing) Then
            Console.WriteLine("The intersection of " + fileDialogPerm1.Access.ToString() + " and " _
            + fileDialogPerm2.Access.ToString() + " = " + CType(fileDialogPerm3, _
            FileDialogPermission).Access.ToString())
        Else
            Console.WriteLine("The intersection of " + fileDialogPerm1.Access.ToString() + " and " + _
            fileDialogPerm2.Access + " is null.")
        End If
        
        Return returnValue
    
    End Function 'IntersectDemo
    
    ' Copy creates and returns an identical copy of the current permission.
    Private Function CopyDemo() As Boolean 
        
        Dim returnValue As Boolean = True
        
        fileDialogPerm2 = CType(fileDialogPerm1.Copy(), FileDialogPermission)
        Console.WriteLine("Result of copy = " + fileDialogPerm2.ToString())
        
        Return returnValue
    
    End Function 'CopyDemo
    
    ' ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
    ' permission with the specified state from the XML encoding.
    Private Function ToFromXmlDemo() As Boolean 
        
        Dim returnValue As Boolean = True
        
        fileDialogPerm2 = New FileDialogPermission(PermissionState.None)
        fileDialogPerm2.FromXml(fileDialogPerm1.ToXml())
        Console.WriteLine("Result of ToFromXml = " + fileDialogPerm2.ToString())
        
        Return returnValue
    
    End Function 'ToFromXmlDemo
    
    ' Invoke all demos.
    Public Function RunDemo() As Boolean
        Dim returnCode As Boolean = True
        Dim tempReturnCode As Boolean

        ' Call the IsSubsetOf demo.
        If IsSubsetOfDemo() Then
            Console.Out.WriteLine("IsSubsetOf demo completed successfully.")
            tempReturnCode = True
        Else
            Console.Out.WriteLine("IsSubsetOf demo failed.")
            tempReturnCode = False
        End If
        returnCode = tempReturnCode And returnCode

        ' Call the Union demo.
        If UnionDemo() Then
            Console.Out.WriteLine("Union demo completed successfully.")
            tempReturnCode = True
        Else
            Console.Out.WriteLine("Union demo failed.")
            tempReturnCode = False
        End If
        returnCode = tempReturnCode And returnCode

        ' Call the Intersect demo.  
        If IntersectDemo() Then
            Console.Out.WriteLine("Intersect demo completed successfully.")
            tempReturnCode = True
        Else
            Console.Out.WriteLine("Intersect demo failed.")
            tempReturnCode = False
        End If
        returnCode = tempReturnCode And returnCode


        ' Call the Copy demo.   
        If CopyDemo() Then
            Console.Out.WriteLine("Copy demo completed successfully.")
            tempReturnCode = True
        Else
            Console.Out.WriteLine("Copy demo failed.")
            tempReturnCode = False
        End If
        returnCode = tempReturnCode And returnCode

        ' Call the ToFromXml demo.  
        If ToFromXmlDemo() Then
            Console.Out.WriteLine("ToFromXml demo completed successfully.")
            tempReturnCode = True
        Else
            Console.Out.WriteLine("ToFromXml demo failed.")
            tempReturnCode = False
        End If
        returnCode = tempReturnCode And returnCode

        Return returnCode
    End Function
     
    ' Test harness.
    Public Shared Sub Main(ByVal args() As String) 
        Try
            Dim democase As New FileDialogPermissionDemo()
            Dim returnCode As Boolean = democase.RunDemo()
            If returnCode Then
                Console.Out.WriteLine("FileDialogPermission demo completed successfully.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 100
            Else
                Console.Out.WriteLine("FileDialogPermission demo failed.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 101
            End If
        Catch e As Exception
            Console.Out.WriteLine("FileDialogPermission failed.")
            Console.WriteLine(e.ToString())
            Console.Out.WriteLine("Press the Enter key to exit.")
            Dim consoleInput As String = Console.ReadLine()
            System.Environment.ExitCode = 101
        End Try
    
    End Sub 'Main
End Class 'FileDialogPermissionDemo
using System;
using System.Security;
using System.Security.Permissions;

[assembly: CLSCompliant(true)]

public class FileDialogPermissionDemo
{
    FileDialogPermission fileDialogPerm1 = new FileDialogPermission(FileDialogPermissionAccess.Open);
    FileDialogPermission fileDialogPerm2 = new FileDialogPermission(FileDialogPermissionAccess.OpenSave);
    FileDialogPermission fileDialogPerm3 = new FileDialogPermission(PermissionState.None);
    // IsSubsetOf determines whether the current permission is a subset of the
    // specified permission.
    private bool IsSubsetOfDemo()
    {
        bool returnValue = true;


        if (fileDialogPerm1.IsSubsetOf(fileDialogPerm2))
        {
            Console.WriteLine(fileDialogPerm1.Access + " is a subset of " +
                fileDialogPerm2.Access);
        }
        else
        {
                        Console.WriteLine(fileDialogPerm1.Access + " is not a subset of " +
                            fileDialogPerm2.Access);
                    }

        return returnValue;
    }

    // Union creates a new permission that is the union of the current permission and the
    // specified permission.
    private bool UnionDemo()
    {
        bool returnValue = true;

                fileDialogPerm3 = (FileDialogPermission)fileDialogPerm1.Union(fileDialogPerm2);

                if (fileDialogPerm3 == null)
                {
                    Console.WriteLine("The union of " + fileDialogPerm1.Access + 
                        " and " + fileDialogPerm2.Access + " is null.");
                }
                else
                {
                    Console.WriteLine("The union of " + fileDialogPerm1.Access + " and " +
                        fileDialogPerm2.Access + " = " +
                        ((FileDialogPermission)fileDialogPerm3).Access.ToString());
                }

        return returnValue;

    }

    // Intersect creates and returns a new permission that is the intersection of the current
    // permission and the permission specified.
    private bool IntersectDemo()
    {
        bool returnValue = true;

        fileDialogPerm3 = (FileDialogPermission)fileDialogPerm1.Intersect(fileDialogPerm2);
        if (fileDialogPerm3 != null)
        {
            Console.WriteLine("The intersection of " + fileDialogPerm1.Access + 
                " and " + fileDialogPerm2.Access + " = " +
                ((FileDialogPermission)fileDialogPerm3).Access.ToString());
        }
        else
        {
            Console.WriteLine("The intersection of " + fileDialogPerm1.Access + 
                " and " + fileDialogPerm2.Access + " is null.");
        }
        
        return returnValue;
    }

    // Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {

        bool returnValue = true;

        fileDialogPerm2 = (FileDialogPermission)fileDialogPerm1.Copy();
        Console.WriteLine("Result of copy = " + fileDialogPerm2.ToString());

        return returnValue;
    }

    // ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
    // permission with the specified state from the XML encoding.
    private bool ToFromXmlDemo()
    {

        bool returnValue = true;

        fileDialogPerm2 = new FileDialogPermission(PermissionState.None);
        fileDialogPerm2.FromXml(fileDialogPerm1.ToXml());
        Console.WriteLine("Result of ToFromXml = " +
            fileDialogPerm2.ToString());

        return returnValue;
    }

    // Invoke all demos.
    public bool RunDemo()
    {
        bool returnCode = true;
        bool tempReturnCode;

        // Call IsSubsetOf demo.
        if (tempReturnCode = IsSubsetOfDemo()) Console.Out.WriteLine("IsSubsetOf demo completed successfully.");
        else Console.Out.WriteLine("IsSubsetOf demo failed.");
        returnCode = tempReturnCode && returnCode;

        // Call Union demo.
        if (tempReturnCode = UnionDemo()) Console.Out.WriteLine("Union demo completed successfully.");
        else Console.Out.WriteLine("Union demo failed.");
        returnCode = tempReturnCode && returnCode;

        // Call Intersect demo.
        if (tempReturnCode = IntersectDemo()) Console.Out.WriteLine("Intersect demo completed successfully.");
        else Console.Out.WriteLine("Intersect demo failed.");
        returnCode = tempReturnCode && returnCode;


        // Call Copy demo.
        if (tempReturnCode = CopyDemo()) Console.Out.WriteLine("Copy demo completed successfully.");
        else Console.Out.WriteLine("Copy demo failed.");
        returnCode = tempReturnCode && returnCode;

        // Call ToFromXml demo.
        if (tempReturnCode = ToFromXmlDemo()) Console.Out.WriteLine("ToFromXml demo completed successfully.");
        else Console.Out.WriteLine("ToFromXml demo failed.");
        returnCode = tempReturnCode && returnCode;

        return (returnCode);

    }
    // Test harness.
    public static void Main(String[] args)
    {
        try
        {
            FileDialogPermissionDemo democase = new FileDialogPermissionDemo();
            bool returnCode = democase.RunDemo();
            if (returnCode)
            {
                Console.Out.WriteLine("FileDialogPermission demo completed successfully.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 100;
            }
            else
            {
                Console.Out.WriteLine("FileDialogPermission demo failed.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 101;
            }
        }
        catch (Exception e)
        {
            Console.Out.WriteLine("FileDialogPermission failed.");
            Console.WriteLine(e.ToString());
            Console.Out.WriteLine("Press the Enter key to exit.");
            string consoleInput = Console.ReadLine();
            System.Environment.ExitCode = 101;
        }
    }
}
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;

// This class generates FileDialogPermission objects.

[assembly:CLSCompliant(true)];
public ref class FileDialogPermissionDemo
{
private:

    // IsSubsetOf determines whether the current permission is a subset of the 
    // specified permission.
    bool IsSubsetOfDemo()
    {
        bool returnValue = true;
        FileDialogPermission^ fileDialogIdPerm1 = gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
        FileDialogPermission^ fileDialogIdPerm2 = gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );
        if ( fileDialogIdPerm1->IsSubsetOf( fileDialogIdPerm2 ) )
        {
            Console::WriteLine( "{0} is a subset of {1}", fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
        }
        else
        {
            Console::WriteLine( "{0} is not a subset of {1}", fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
        }

        return returnValue;
    }


    // Union creates a new permission that is the union of the current permission and the 
    // specified permission.
    bool UnionDemo()
    {
        bool returnValue = true;
        FileDialogPermission^ fileDialogIdPerm1 = gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
        FileDialogPermission^ fileDialogIdPerm2 = gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );
        FileDialogPermission^ fileDialogIdPerm3 = gcnew FileDialogPermission(PermissionState::None);
        fileDialogIdPerm3 = dynamic_cast<FileDialogPermission^>(fileDialogIdPerm1->Union( fileDialogIdPerm2 ));
        if ( fileDialogIdPerm3 == nullptr )
        {
            Console::WriteLine( "The union of {0} and {1} is null.", 
                fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
        }
        else
        {
            Console::WriteLine( "The union of {0} and {1} = {2}", 
                fileDialogIdPerm1->Access, fileDialogIdPerm2->Access, (dynamic_cast<FileDialogPermission^>(fileDialogIdPerm3))->Access );
        }
        return returnValue;
    }


    // Intersect creates and returns a new permission that is the intersection of the current 
    // permission and the permission specified.
    bool IntersectDemo()
    {
        bool returnValue = true;
        FileDialogPermission^ fileDialogIdPerm1 = 
            gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
        FileDialogPermission^ fileDialogIdPerm2 = 
            gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );

        FileDialogPermission^ fileDialogIdPerm3 = 
            gcnew FileDialogPermission(PermissionState::None);

        //Console.WriteLine("\tfileDialogIdPerm2 = " +fileDialogIdPerm2.ToString());
        fileDialogIdPerm3 = dynamic_cast<FileDialogPermission^>(fileDialogIdPerm1->Intersect( fileDialogIdPerm2 ));
        if ( fileDialogIdPerm3 != nullptr )
        {
            Console::WriteLine( "The intersection of {0} and {1} = {2}", 
                fileDialogIdPerm1->Access, fileDialogIdPerm2->Access, (dynamic_cast<FileDialogPermission^>(fileDialogIdPerm3))->Access );
        }
        else
        {
            Console::WriteLine( "The intersection of {0} and {1} is null.", 
                fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
        }

        return returnValue;
    }


    // Copy creates and returns an identical copy of the current permission.
    bool CopyDemo()
    {
        bool returnValue = true;
        FileDialogPermission^ fileDialogIdPerm1 = gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
        FileDialogPermission^ fileDialogIdPerm2 = gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );

        FileDialogPermission^ fileDialogIdPerm3 = gcnew FileDialogPermission(PermissionState::None);

        fileDialogIdPerm2 = dynamic_cast<FileDialogPermission^>(fileDialogIdPerm1->Copy());
        Console::WriteLine( "Result of copy = {0}", fileDialogIdPerm2 );

        return returnValue;
    }


    // ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a 
    // permission with the specified state from the XML encoding. 
    bool ToFromXmlDemo()
    {
        bool returnValue = true;
        FileDialogPermission^ fileDialogIdPerm1 = gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
        FileDialogPermission^ fileDialogIdPerm2 = gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );

        FileDialogPermission^ fileDialogIdPerm3 = gcnew FileDialogPermission(PermissionState::None);

        fileDialogIdPerm2 = gcnew FileDialogPermission( PermissionState::None );
        fileDialogIdPerm2->FromXml( fileDialogIdPerm1->ToXml() );
        Console::WriteLine( "Result of ToFromXml = {0}", fileDialogIdPerm2 );

        return returnValue;
    }


public:

    // Invoke all demos.
    bool RunDemo()
    {
        bool returnCode = true;
        bool tempReturnCode;

        // Call IsSubsetOf demo.
        if ( tempReturnCode = IsSubsetOfDemo() )
            Console::WriteLine( "IsSubsetOf demo completed successfully." );
        else
            Console::WriteLine( "IsSubsetOf demo failed." );

        returnCode = tempReturnCode && returnCode;

        // Call Union demo.
        if ( tempReturnCode = UnionDemo() )
            Console::WriteLine( "Union demo completed successfully." );
        else
            Console::WriteLine( "Union demo failed." );

        returnCode = tempReturnCode && returnCode;

        // Call Intersect demo. 
        if ( tempReturnCode = IntersectDemo() )
            Console::WriteLine( "Intersect demo completed successfully." );
        else
            Console::WriteLine( "Intersect demo failed." );

        returnCode = tempReturnCode && returnCode;

        // Call Copy demo. 
        if ( tempReturnCode = CopyDemo() )
            Console::WriteLine( "Copy demo completed successfully." );
        else
            Console::WriteLine( "Copy demo failed." );

        returnCode = tempReturnCode && returnCode;

        // Call ToFromXml demo. 
        if ( tempReturnCode = ToFromXmlDemo() )
            Console::WriteLine( "ToFromXml demo completed successfully." );
        else
            Console::WriteLine( "ToFromXml demo failed." );

        returnCode = tempReturnCode && returnCode;
        return (returnCode);
    }

};


// Test harness.
int main()
{
    try
    {
        FileDialogPermissionDemo^ democase = gcnew FileDialogPermissionDemo;
        bool returnCode = democase->RunDemo();
        if ( returnCode )
        {
            Console::WriteLine( "FileDialogPermission demo completed successfully." );
            Console::WriteLine( "Press the Enter key to exit." );
            Console::ReadLine();
            System::Environment::ExitCode = 100;
        }
        else
        {
            Console::WriteLine( "FileDialogPermission demo failed." );
            Console::WriteLine( "Press the Enter key to exit." );
            Console::ReadLine();
            System::Environment::ExitCode = 101;
        }
    }
    catch ( Exception^ e ) 
    {
        Console::WriteLine( "FileDialogPermission failed." );
        Console::WriteLine( e );
        Console::WriteLine( "Press the Enter key to exit." );
        Console::ReadLine();
        System::Environment::ExitCode = 101;
    }

}
// This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, 
// ToXml and FromXml methods
// of the FileDialogPermission class.
import System .* ;
import System.Security .* ;
import System.Security.Permissions .* ;

/** @assembly CLSCompliant(true)
 */

public class FileDialogPermissionDemo
{
    // IsSubsetOf determines whether the current permission is a subset of the
    // specified permission.
    private boolean IsSubsetOfDemo() 
    {
        boolean returnValue = true;
        FileDialogPermissionAccess fileDialog1[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermissionAccess fileDialog2[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermission fileDialogIdPerm1[] = 
            new FileDialogPermission[1];
        FileDialogPermission fileDialogIdPerm2[] = 
            new FileDialogPermission[1];
        FileDialogGenerator fileDialogGen1 =  
            new FileDialogGenerator();
        FileDialogGenerator fileDialogGen2 =  
            new FileDialogGenerator();
        fileDialogGen1.ResetIndex();
        while(fileDialogGen1.CreateFileDialog
            (fileDialogIdPerm1, fileDialog1)) {
            if (fileDialogIdPerm1[0] == null) {
                continue ;
            }
            fileDialogGen2.ResetIndex();
            Console.WriteLine("**********************" 
                + "**********************************\n");
            
            while(fileDialogGen2.CreateFileDialog(
                fileDialogIdPerm2, fileDialog2)) {
                if (fileDialogIdPerm2[0] == null) {
                    continue ;
                }
                try {
                    if (fileDialogIdPerm1[0].
                        IsSubsetOf(fileDialogIdPerm2[0])) {
                        Console.WriteLine((fileDialogIdPerm1[0].get_Access() 
                            + " is a subset of " 
                            + fileDialogIdPerm2[0].get_Access()));
                    }
                    else {
                        Console.WriteLine((fileDialogIdPerm1[0].get_Access() 
                            + " is not a subset of " + 
                        fileDialogIdPerm2[0].get_Access()));
                    }
                }
                catch(System.Exception  e){
                    Console.WriteLine(("An exception was thrown " 
                        + "for subset :" + fileDialogIdPerm1[0] 
                        + "\n" + fileDialogIdPerm2[0] + "\n" + e));
                        returnValue = false;
                }
            }
        }
        return returnValue ;
    } //IsSubsetOfDemo

    // Union creates a new permission that is the union of 
    // the current permission and the
    // specified permission.
    private boolean UnionDemo() 
    {
        boolean returnValue = true;
        FileDialogPermissionAccess fileDialog1[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermissionAccess fileDialog2[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermission fileDialogIdPerm1[] = 
            new FileDialogPermission[1];
        FileDialogPermission fileDialogIdPerm2[] = 
            new FileDialogPermission[1];
        IPermission fileDialogIdPerm3;
        FileDialogGenerator fileDialogGen1 =  
            new FileDialogGenerator();
        FileDialogGenerator fileDialogGen2 =  
            new FileDialogGenerator();
        fileDialogGen1.ResetIndex();
        while(fileDialogGen1.CreateFileDialog(fileDialogIdPerm1, 
            fileDialog1)) {
            if (fileDialogIdPerm1[0] == null) {
                continue ;
            }
            Console.WriteLine("************************" 
                + "**********************************\n");
            fileDialogGen2.ResetIndex();
            
            while(fileDialogGen2.CreateFileDialog(fileDialogIdPerm2, 
                fileDialog2)) {
                if (fileDialogIdPerm2[0] == null) {
                    continue ;
                }
                fileDialogIdPerm3 =((FileDialogPermission)(
                    fileDialogIdPerm1[0].Union(fileDialogIdPerm2[0])));
                fileDialogIdPerm3 = fileDialogIdPerm1[0].
                    Union(fileDialogIdPerm2[0]);
                
                if (fileDialogIdPerm3 == null) {
                    Console.WriteLine(("The union of " + fileDialog1[0] 
                        + " and " + fileDialog2[0] + " is null."));
                }
                else {
                    Console.WriteLine(("The union of " 
                        + fileDialogIdPerm1[0].get_Access() + " and " 
                        + fileDialogIdPerm2[0].get_Access() + " = " 
                        + ((FileDialogPermission)(fileDialogIdPerm3)).
                        get_Access().ToString()));
                }
            }
        }
        return returnValue ;
    } //UnionDemo

    // Intersect creates and returns a new permission that is the 
    // intersection of the current
    // permission and the permission specified.
    private boolean IntersectDemo() 
    {
        boolean returnValue = true;
        FileDialogPermissionAccess fileDialog1[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermissionAccess fileDialog2[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermission fileDialogIdPerm1[] = 
            new FileDialogPermission[1];
        FileDialogPermission fileDialogIdPerm2[] = 
            new FileDialogPermission[1];
        FileDialogPermission fileDialogIdPerm3 = null;
        FileDialogGenerator fileDialogGen1 =  
            new FileDialogGenerator();
        FileDialogGenerator fileDialogGen2 =  
            new FileDialogGenerator();
        fileDialogGen1.ResetIndex();
        while(fileDialogGen1.CreateFileDialog(
            fileDialogIdPerm1, fileDialog1)) {
            if (fileDialogIdPerm1[0] == null) {
                continue ;
            }
            Console.WriteLine("***************************" 
                + "*******************************\n");
            fileDialogGen2.ResetIndex();
            
            while(fileDialogGen2.CreateFileDialog(
                fileDialogIdPerm2, fileDialog2)) {
                if (fileDialogIdPerm2[0] == null) {
                    continue ;
                }
                
                fileDialogIdPerm3 =((FileDialogPermission)
                    (fileDialogIdPerm1[0].Intersect
                    (fileDialogIdPerm2[0])));
                if (fileDialogIdPerm3  != null) {
                    Console.WriteLine(("The intersection of " 
                        + fileDialog1[0] + " and " + fileDialog2[0] 
                        + " = " +((FileDialogPermission)(fileDialogIdPerm3)).
                        get_Access().ToString()));
                }
                else {
                    Console.WriteLine(("The intersection of " 
                        + fileDialog1[0] + " and " + fileDialog2[0] 
                        + " is null."));
                }
            }
        }
        return returnValue ;
    } //IntersectDemo

    // Copy creates and returns an identical copy of the current permission.
    private boolean CopyDemo() 
    {
        boolean returnValue = true;
        FileDialogPermissionAccess fileDialog1[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermission fileDialogIdPerm1[] = 
            new FileDialogPermission[1];
        FileDialogPermission fileDialogIdPerm2[] = 
            new FileDialogPermission[1];
        FileDialogGenerator fileDialogGen1 =  
            new FileDialogGenerator();
        FileDialogGenerator fileDialogGen2 =  
            new FileDialogGenerator();

        fileDialogGen1.ResetIndex();
        while(fileDialogGen1.CreateFileDialog(fileDialogIdPerm1, 
            fileDialog1)) {
            if ( fileDialogIdPerm1[0] == null  ) {
                continue ;
            }
            fileDialogGen2.ResetIndex();
            Console.WriteLine("************************" 
                + "********************************\n");
            try {
                fileDialogIdPerm2[0] =(
                    (FileDialogPermission)(fileDialogIdPerm1[0].Copy()));
                Console.WriteLine(("Result of copy = " 
                    + fileDialogIdPerm2[0].ToString()));
            } 
            catch(System.Exception  e) {
                Console.WriteLine(("Copy failed :" 
                    + fileDialogIdPerm1[0].ToString() + e));
                continue ;
            }
        }
        return returnValue ;
    } //CopyDemo   

    // ToXml creates an XML encoding of the permission and its current 
    // state; FromXml reconstructs a
    // permission with the specified state from the XML encoding.
    private boolean ToFromXmlDemo() 
    {
        boolean returnValue = true;      
        FileDialogPermissionAccess fileDialog1[] = 
            new FileDialogPermissionAccess[1];
        FileDialogPermission fileDialogIdPerm1[] = 
            new FileDialogPermission[1];
        FileDialogPermission fileDialogIdPerm2[] = 
            new FileDialogPermission[1];
        FileDialogGenerator fileDialogGen1 =  
            new FileDialogGenerator();
        FileDialogGenerator fileDialogGen2 =  
            new FileDialogGenerator();
        fileDialogGen1.ResetIndex();
        while(fileDialogGen1.CreateFileDialog(fileDialogIdPerm1, 
            fileDialog1)) {
            if (fileDialogIdPerm1[0] == null) {
                continue ;
            }
            Console.WriteLine("************************" 
                + "********************************\n");
            fileDialogGen2.ResetIndex();
            try {
                fileDialogIdPerm2[0] = 
                    new FileDialogPermission(PermissionState.None);
                fileDialogIdPerm2[0].FromXml(fileDialogIdPerm1[0].ToXml());
                Console.WriteLine(("Result of ToFromXml = " 
                    + fileDialogIdPerm2[0].ToString()));
            }
            catch(System.Exception  e) {
                Console.WriteLine(("ToFromXml failed :" 
                    + fileDialogIdPerm1[0].ToString() + e));
                continue ;
            }
        }
        return returnValue ;
    } //ToFromXmlDemo    

    // Invoke all demos.
    public boolean RunDemo() 
    {
        boolean returnCode = true;
        boolean tempReturnCode;

        // Call IsSubsetOf demo.
        if (tempReturnCode = IsSubsetOfDemo()) {
            Console.get_Out().WriteLine("IsSubsetOf demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("IsSubsetOf demo failed.");
        }
        returnCode = tempReturnCode && returnCode;

        // Call Union demo.
        if (tempReturnCode = UnionDemo()) {
            Console.get_Out().WriteLine("Union demo " 
                + "completed successfully.");
        }
        else {
            Console.get_Out().WriteLine("Union demo failed.");
        }
        returnCode = tempReturnCode && returnCode;

        // Call Intersect demo.
        if (tempReturnCode = IntersectDemo()) {
            Console.get_Out().WriteLine("Intersect demo completed " 
                + "successfully.");
        }
        else {
            Console.get_Out().WriteLine("Intersect demo failed.");
        }
        returnCode = tempReturnCode && returnCode;

        // Call Copy demo.
        if (tempReturnCode = CopyDemo()) {
            Console.get_Out().WriteLine("Copy demo completed " 
                + "successfully.");
        }
        else {
            Console.get_Out().WriteLine("Copy demo failed.");
        }
        returnCode = tempReturnCode && returnCode;

        // Call ToFromXml demo.
        if (tempReturnCode = ToFromXmlDemo()) {
            Console.get_Out().WriteLine("ToFromXml demo completed " 
                + "successfully.");
        }
        else {
            Console.get_Out().WriteLine("ToFromXml demo failed.");
        }
        returnCode = tempReturnCode && returnCode;
        return returnCode ;
    } //RunDemo   
 
    // Test harness.
    public static void main(String[] args)
    {
        try {
            FileDialogPermissionDemo democase =  
                new FileDialogPermissionDemo();
            boolean returnCode = democase.RunDemo();
            if (returnCode) {
                Console.get_Out().WriteLine("FileDialogPermission demo " 
                    + "completed successfully.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                System.Environment.set_ExitCode(100);
            }
            else {
                Console.get_Out().WriteLine("FileDialogPermission demo " 
                    + "failed.");
                Console.get_Out().WriteLine("Press the Enter key to exit.");
                String consoleInput = Console.ReadLine();
                System.Environment.set_ExitCode(101);
            }
        }
        catch(System.Exception  e){
            Console.get_Out().WriteLine("FileDialogPermission failed.");
            Console.WriteLine(e.ToString());
            Console.get_Out().WriteLine("Press the Enter key to exit.");
            String consoleInput = Console.ReadLine();
            System.Environment.set_ExitCode(101);
        }
    } //main
} //FileDialogPermissionDemo

// This class generates FileDialogPermission objects.
class FileDialogGenerator
{
    private FileDialogPermissionAccess myFileDialog[] =  
        {FileDialogPermissionAccess.None, 
            FileDialogPermissionAccess.Open, 
            FileDialogPermissionAccess.OpenSave, 
            FileDialogPermissionAccess.Save};   
    private int fileDialogIndex = 0;   

    public FileDialogGenerator() 
    {
        ResetIndex();
    } //FileDialogGenerator

    public void ResetIndex() 
    {
        fileDialogIndex = 0;
    } //ResetIndex   

    // Create a FileDialogPermission.
    public boolean CreateFileDialog(FileDialogPermission fileDialogPerm[], 
        FileDialogPermissionAccess fileDialog[]) 
    {
        if (fileDialogIndex >= myFileDialog.length) {
            fileDialogPerm[0] = new FileDialogPermission(PermissionState.None);
            fileDialog[0] = FileDialogPermissionAccess.None;
            return false ;
        }
        fileDialog[0] = myFileDialog[fileDialogIndex++];
        try {
            fileDialogPerm[0] = new FileDialogPermission(fileDialog[0]);
            return true ;
        }
        catch(System.Exception  e) {
            Console.WriteLine(("Cannot create FileDialogPermission: " 
                + fileDialog + " " + e));
            fileDialogPerm[0] = new FileDialogPermission(PermissionState.None);
            fileDialog[0] = FileDialogPermissionAccess.None;
            return true ;
        }
    } //CreateFileDialog
} //FileDialogGenerator

Vererbungshierarchie

System.Object
   System.Security.CodeAccessPermission
    System.Security.Permissions.FileDialogPermission

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

FileDialogPermission-Member
System.Security.Permissions-Namespace
FileDialogPermissionAttribute
FileDialogPermissionAccess

Weitere Ressourcen

Sicherheitsberechtigungen
Anfordern von Berechtigungen