FileDialogPermission.FromXml 方法

从 XML 编码重新构造具有指定状态的权限。

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

语法

声明
Public Overrides Sub FromXml ( _
    esd As SecurityElement _
)
用法
Dim instance As FileDialogPermission
Dim esd As SecurityElement

instance.FromXml(esd)
public override void FromXml (
    SecurityElement esd
)
public:
virtual void FromXml (
    SecurityElement^ esd
) override
public void FromXml (
    SecurityElement esd
)
public override function FromXml (
    esd : SecurityElement
)

参数

  • esd
    用于重新构造权限的 XML 编码。

异常

异常类型 条件

ArgumentNullException

esd 参数为 空引用(在 Visual Basic 中为 Nothing)。

ArgumentException

esd 参数不是有效的权限元素。

- 或 -

不支持 esd 参数的版本号。

示例

下面的代码示例旨在演示 FromXml 方法的行为,而不演示其用法。一般情况下,权限类的方法由安全性基础结构使用,而不在应用程序中使用。但是,下面的代码示例将演示在从您的代码执行该方法时,该方法将如何执行。有关完整的代码示例,请参见 FileDialogPermission 类。

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
private bool ToFromXmlDemo()
{

    bool returnValue = true;

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

    return returnValue;
}
    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:
// 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    

平台

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

请参见

参考

FileDialogPermission 类
FileDialogPermission 成员
System.Security.Permissions 命名空间