Export (0) Print
Expand All

RegistryPermission.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 to use 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 valid.

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 reg1 As String
    Dim regPerm1, regPerm2 As RegistryPermission

    Dim regGen1 As New regGenerator()
    Dim regGen2 As New regGenerator()

    regGen1.ResetIndex()
    While regGen1.CreateReg(regPerm1, reg1, RegistryPermissionAccess.Read)
        If regPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("********************************************************" & ControlChars.Lf)
        regGen2.ResetIndex()
        Try
            regPerm2 = New RegistryPermission(PermissionState.None)
            regPerm2.FromXml(regPerm1.ToXml())
            Console.WriteLine(("Result of ToFromXml = " & regPerm2.ToString() & ControlChars.Lf))

        Catch e As Exception
            Console.WriteLine(("ToFromXml failed :" & regPerm1.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 reg1;
    RegistryPermission regPerm1,regPerm2;

    RegGenerator regGen1 = new RegGenerator();
    RegGenerator regGen2 = new RegGenerator();

    regGen1.ResetIndex();
    while(regGen1.CreateReg(out regPerm1, out reg1, RegistryPermissionAccess.Read)) 
    {
        if(regPerm1 == null) continue;
        Console.WriteLine("********************************************************\n");
        regGen2.ResetIndex();
        try
        {            
            regPerm2= new RegistryPermission(PermissionState.None);
            regPerm2.FromXml(regPerm1.ToXml());
            Console.WriteLine("Result of ToFromXml = " +regPerm2.ToString() + "\n");
        
        }
        catch(Exception e) 
        {
            Console.WriteLine("ToFromXml failed :" + regPerm1.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. 
bool ToFromXmlDemo()
{

    bool returnValue = true;

    String* reg1;
    RegistryPermission* regPerm1;
    RegistryPermission* regPerm2;

    RegGenerator* regGen1 = new RegGenerator();
    RegGenerator* regGen2 = new RegGenerator();

    regGen1->ResetIndex();
    while(regGen1->CreateReg(&regPerm1, &reg1, RegistryPermissionAccess::Read)) 
    {
        if(regPerm1 == 0) continue;
        Console::WriteLine(S"********************************************************\n");
        regGen2->ResetIndex();
        try
        {            
            regPerm2= new RegistryPermission(PermissionState::None);
            regPerm2->FromXml(regPerm1->ToXml());
            Console::WriteLine(S"Result of ToFromXml = {0}\n", regPerm2);

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

See Also

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

Show:
© 2014 Microsoft