Export (0) Print
Expand All

FileDialogPermission.ToXml Method

Creates an XML encoding of the permission and its current state.

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

Return Value

An XML encoding of the permission, including state information.

Implements

ISecurityEncodable.ToXml

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 fileDialog1 As FileDialogPermissionAccess
    Dim fileDialogIdPerm1, fileDialogIdPerm2 As FileDialogPermission
    Dim fileDialogGen1 As New FileDialogGenerator()
    Dim fileDialogGen2 As New FileDialogGenerator()
    fileDialogGen1.ResetIndex()
    While fileDialogGen1.CreateFileDialog(fileDialogIdPerm1, fileDialog1)
        If fileDialogIdPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("********************************************************" & ControlChars.Lf)
        fileDialogGen2.ResetIndex()
        Try
            fileDialogIdPerm2 = New FileDialogPermission(PermissionState.None)
            fileDialogIdPerm2.FromXml(fileDialogIdPerm1.ToXml())
            Console.WriteLine(("Result of ToFromXml = " & fileDialogIdPerm2.ToString()))

        Catch e As Exception
            Console.WriteLine(("ToFromXml failed :" & fileDialogIdPerm1.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;

    FileDialogPermissionAccess fileDialog1;
    FileDialogPermission fileDialogIdPerm1,fileDialogIdPerm2;
    FileDialogGenerator fileDialogGen1 = new FileDialogGenerator();
    FileDialogGenerator fileDialogGen2 = new FileDialogGenerator();
    fileDialogGen1.ResetIndex();
    while(fileDialogGen1.CreateFileDialog(out fileDialogIdPerm1, out fileDialog1)) 
    {
        if(fileDialogIdPerm1 == null) continue;
        Console.WriteLine("********************************************************\n");
        fileDialogGen2.ResetIndex();
        try
        {            
            fileDialogIdPerm2= new FileDialogPermission(PermissionState.None);
            fileDialogIdPerm2.FromXml(fileDialogIdPerm1.ToXml());
            Console.WriteLine("Result of ToFromXml = " +
                fileDialogIdPerm2.ToString());

        }
        catch(Exception e) 
        {
            Console.WriteLine("ToFromXml failed :" + fileDialogIdPerm1.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;

   FileDialogPermissionAccess fileDialog1;
   FileDialogPermission* fileDialogIdPerm1;
   FileDialogPermission* fileDialogIdPerm2;

   FileDialogGenerator* fileDialogGen1 = new FileDialogGenerator();
   FileDialogGenerator* fileDialogGen2 = new FileDialogGenerator();
   fileDialogGen1->ResetIndex();
   while(fileDialogGen1->CreateFileDialog(&fileDialogIdPerm1, &fileDialog1)) 
   {
      if(fileDialogIdPerm1 == 0) continue;
      Console::WriteLine(S"********************************************************\n");
      fileDialogGen2->ResetIndex();
      try
      {            
         fileDialogIdPerm2= new FileDialogPermission(PermissionState::None);
         fileDialogIdPerm2->FromXml(fileDialogIdPerm1->ToXml());
         Console::WriteLine(S"Result of ToFromXml = {0}", fileDialogIdPerm2);

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

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

Show:
© 2015 Microsoft