Export (0) Print
Expand All

FileIOPermission.FromXml Method

Reconstructs a permission with a specified state from an XML encoding.

[Visual Basic]
Overrides Public Sub FromXml( _
   ByVal esd As SecurityElement _
) Implements ISecurityEncodable.FromXml
[C#]
public override void FromXml(
 SecurityElement esd
);
[C++]
public: void FromXml(
 SecurityElement* esd
);
[JScript]
public override function FromXml(
   esd : SecurityElement
);

Parameters

esd
The XML encoding used to reconstruct the permission.

Implements

ISecurityEncodable.FromXml

Exceptions

Exception Type Condition
ArgumentNullException The esd parameter is a null reference (Nothing in Visual Basic).
ArgumentException The esd parameter is not a valid permission element.

-or-

The esd parameter's version number is not compatible.

Example

[Visual Basic] 
' 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

    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 fileIOPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("********************************************************" & ControlChars.Lf)
        fileIOGen2.ResetIndex()
        Try
            fileIOPerm2 = New FileIOPermission(PermissionState.None)
            fileIOPerm2.FromXml(fileIOPerm1.ToXml())
            Console.WriteLine(("Result of ToFromXml = " & fileIOPerm2.ToString() & ControlChars.Lf))

        Catch e As Exception
            Console.WriteLine(("ToFromXml failed :" & fileIOPerm1.ToString() & e.ToString()))
            GoTo ContinueWhile1
        End Try
ContinueWhile1:
    End While

    Return returnValue
End Function 'ToFromXmlDemo


[C#] 
// 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;

        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(fileIOPerm1 == null) continue;
            Console.WriteLine("********************************************************\n");
            fileIOGen2.ResetIndex();
            try
            {            
                fileIOPerm2= new FileIOPermission(PermissionState.None);
                fileIOPerm2.FromXml(fileIOPerm1.ToXml());
                Console.WriteLine("Result of ToFromXml = " +fileIOPerm2.ToString() + "\n");
            
            }
            catch(Exception e) 
            {
                Console.WriteLine("ToFromXml failed :" + fileIOPerm1.ToString() + e);
                continue;
            }
        }

        return returnValue;

    }

[C++] 
// 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;

    String* fileIO1;
    FileIOPermission* fileIOPerm1;
    FileIOPermission* fileIOPerm2;


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

    fileIOGen1->ResetIndex();
    while(fileIOGen1->CreateFilePath(&fileIOPerm1, &fileIO1, FileIOPermissionAccess::Read)) 
    {
        if(fileIOPerm1 == 0) continue;
        Console::WriteLine(S"********************************************************\n");
        fileIOGen2->ResetIndex();
        try
        {            
            fileIOPerm2= new FileIOPermission(PermissionState::None);
            fileIOPerm2->FromXml(fileIOPerm1->ToXml());
            Console::WriteLine(S"Result of ToFromXml = {0}\n", fileIOPerm2);

        }
        catch(Exception* e) 
        {
            Console::WriteLine(S"ToFromXml failed :{0}{1}", fileIOPerm1, 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:
© 2014 Microsoft