Copy Method

FileIOPermission.Copy Method

Creates and returns an identical copy of the current permission.

[Visual Basic]
Overrides Public Function Copy() As IPermission Implements _
   IPermission.Copy
[C#]
public override IPermission Copy();
[C++]
public: IPermission* Copy();
[JScript]
public override function Copy() : IPermission;

Return Value

A copy of the current permission.

Implements

IPermission.Copy

Remarks

A copy of the permission represents the same access to resources as the original permission.

Example

[Visual Basic] 
'Copy creates and returns an identical copy of the current permission.
Private Function CopyDemo() As Boolean
    Dim returnValue As Boolean = True
    Dim fileIO1 As String
    Dim fileIOPerm1, fileIOPerm2 As FileIOPermission
    Dim fileIOGen1 As New FileIOGenerator()
    Dim fileIOGen2 As New FileIOGenerator()

    fileIOGen1.ResetIndex()
    While fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1, FileIOPermissionAccess.Read)
        If fileIO1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("**********************************************************" & ControlChars.Lf)
        fileIOGen2.ResetIndex()
        Try
            fileIOPerm2 = CType(fileIOPerm1.Copy(), FileIOPermission)
            If Not (fileIOPerm2 Is Nothing) Then
                Console.WriteLine(("Result of copy = " & fileIOPerm2.ToString() & ControlChars.Lf))
            Else
                Console.WriteLine("Result of copy is null. " & ControlChars.Lf)
            End If
        Catch e As Exception
            If (True.ToString()) Then
                If fileIO1 = "" Then
                    Console.WriteLine("The target FileIOPermission is empty, copy failed.")

                Else
                    Console.WriteLine(e.ToString())
                End If
            End If
            GoTo ContinueWhile1
        End Try
ContinueWhile1:
    End While
    Return returnValue
End Function 'CopyDemo


[C#] 
//Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {
        bool returnValue = true;
        string fileIO1;
        FileIOPermission fileIOPerm1,fileIOPerm2;
        FileIOGenerator fileIOGen1 = new FileIOGenerator();
        FileIOGenerator fileIOGen2 = new FileIOGenerator();

        fileIOGen1.ResetIndex();
        while(fileIOGen1.CreateFilePath(out fileIOPerm1, out fileIO1, FileIOPermissionAccess.Read)) 
        {
            if(fileIO1 == null ) continue;  
            Console.WriteLine("**********************************************************\n");
            fileIOGen2.ResetIndex();
            try
            {            
                fileIOPerm2 = (FileIOPermission)fileIOPerm1.Copy();
                if (fileIOPerm2 != null)
                {
                    Console.WriteLine("Result of copy = " + fileIOPerm2.ToString() + "\n");
                }
                else
                {
                    Console.WriteLine("Result of copy is null. \n");
                }
            }
            catch(Exception e) 
            {
            {
                if (fileIO1 == "")
                {
                    Console.WriteLine( "The target FileIOPermission is empty, copy failed.");

                }
                else
                    Console.WriteLine( e);
            }
                continue;
            }
        }
        return returnValue;
    }

[C++] 
//Copy creates and returns an identical copy of the current permission.
private:
bool CopyDemo()
{
    bool returnValue = true;
    String* fileIO1;
    FileIOPermission* fileIOPerm1;
    FileIOPermission* fileIOPerm2;

    FileIOGenerator* fileIOGen1 = new FileIOGenerator();
    FileIOGenerator* fileIOGen2 = new FileIOGenerator();

    fileIOGen1->ResetIndex();
    while(fileIOGen1->CreateFilePath(&fileIOPerm1, &fileIO1, FileIOPermissionAccess::Read)) 
    {
        if(fileIO1 == 0 ) continue;  
        Console::WriteLine(S"**********************************************************\n");
        fileIOGen2->ResetIndex();
        try
        {            
            fileIOPerm2 = dynamic_cast<FileIOPermission*>(fileIOPerm1->Copy());
            if (fileIOPerm2 != 0)
            {
                Console::WriteLine(S"Result of copy = {0}\n", fileIOPerm2);
            }
            else
            {
                Console::WriteLine(S"Result of copy is null. \n");
            }
        }
        catch(Exception* e) 
        {
            {
                if (fileIO1->Equals(S""))
                {
                    Console::WriteLine( S"The target FileIOPermission is empty, copy failed.");

                }
                else
                    Console::WriteLine(e);
            }
            continue;
        }
    }
    return returnValue;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

FileIOPermission Class | FileIOPermission Members | System.Security.Permissions Namespace

Show:
© 2016 Microsoft