FileDialogPermissionAttribute コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > FileDialogPermissionAttribute コンストラクタの意味・解説 

FileDialogPermissionAttribute コンストラクタ

SecurityAction指定して、FileDialogPermissionAttribute クラス新しインスタンス初期化します。

名前空間: System.Security.Permissions
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    action As SecurityAction _
)
Dim action As SecurityAction

Dim instance As New FileDialogPermissionAttribute(action)
public FileDialogPermissionAttribute (
    SecurityAction action
)
public:
FileDialogPermissionAttribute (
    SecurityAction action
)
public FileDialogPermissionAttribute (
    SecurityAction action
)
public function FileDialogPermissionAttribute
 (
    action : SecurityAction
)

パラメータ

action

SecurityAction 値の 1 つ

使用例使用例
' This sample demonstrates the use of the FileDialogPermissionAttribute.
Imports System
Imports System.Reflection
Imports System.Security.Permissions
Imports System.Security
Imports System.IO
Imports Microsoft.VisualBasic



Class [MyClass]

    Public Shared Sub FileDialogPermissionAttributeDemo()
        Try
            PermitOnlyMethod()
        Catch e As Exception
            Console.WriteLine(e.Message.ToString())
        End Try
        Try
            DenyMethod()
        Catch e As Exception
            Console.WriteLine(e.Message.ToString())
        End Try
        Try
            DenyAllMethod()
        Catch e As Exception
            Console.WriteLine(e.Message.ToString())
        End Try
    End Sub 'FileDialogPermissionAttributeDemo


    ' This method demonstrates PermitOnly with the Open property set
 to true.
    <FileDialogPermissionAttribute(SecurityAction.PermitOnly, Open:=True)>
 _
    Public Shared Sub PermitOnlyMethod()
        Console.WriteLine("Executing PermitOnlyMethod.")
        Console.WriteLine("PermitOnly the Open permission.")
        PermitOnlyTest()
    End Sub 'PermitOnlyMethod

    Public Shared Sub PermitOnlyTest()
        Console.WriteLine("Executing PermitOnlyTest.")
        Try
            Dim ps As New
 PermissionSet(PermissionState.None)
            ps.AddPermission(New FileDialogPermission(FileDialogPermissionAccess.Open))
            Console.WriteLine("Demanding permission to open a
 file.")
            ps.Demand()
            Console.WriteLine("Demand succeeded.")
            ps.AddPermission(New FileDialogPermission(FileDialogPermissionAccess.Save))
            Console.WriteLine("Demanding permission to save a
 file.")
            ' This demand should cause an exception.
            ps.Demand()
            ' The TestFailed method is called if an exception is not
 thrown.
        Catch e As Exception
            Console.WriteLine(("An exception was thrown because
 of a save demand: " & e.Message))
        End Try
    End Sub 'PermitOnlyTest


    ' Set the Save property for a Deny action.
    <FileDialogPermissionAttribute(SecurityAction.Deny, Save:=True)> _
    Public Shared Sub DenyMethod()

        Console.WriteLine("Executing DenyMethod.")
        Console.WriteLine("Denying the Save permission.")
        DenyTest()
    End Sub 'DenyMethod

    Public Shared Sub DenyTest()
        Console.WriteLine("Executing DenyTest.")
        Try
            Dim ps As New
 PermissionSet(PermissionState.None)
            ps.AddPermission(New FileDialogPermission(FileDialogPermissionAccess.Open))
            Console.WriteLine("Demanding permission to open a
 file.")
            ps.Demand()
            Console.WriteLine("Demand succeeded.")
            ps.AddPermission(New FileDialogPermission(FileDialogPermissionAccess.Save))
            Console.WriteLine("Demanding permission to save a
 file.")
            ' This demand should cause an exception.
            ps.Demand()
            ' The TestFailed method is called if an exception is not
 thrown.
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("An exception was thrown because
 of an open demand: " & e.Message))
        End Try
    End Sub 'DenyTest


    ' This method demonstrates the use of the FileDialogPermissionAttribute
 to deny all permissions.
    <FileDialogPermissionAttribute(SecurityAction.Deny, Unrestricted:=True)>
 _
    Public Shared Sub DenyAllMethod()
        Console.WriteLine("Executing DenyAllMethod.")
        Console.WriteLine("Denied all FileDialogPermissions ")

        DenyAllTestMethod()
    End Sub 'DenyAllMethod

    ' This method tests to assure permissions have been denied.
    Public Shared Sub DenyAllTestMethod()
        Console.WriteLine("Executing DenyAllTestMethod.")
        Try
            Dim ps As New
 PermissionSet(PermissionState.None)
            ps.AddPermission(New FileDialogPermission(FileDialogPermissionAccess.Open))
            Console.WriteLine("Demanding permission to open a
 file.")
            ' This demand should cause an exception.
            ps.Demand()
            ' The TestFailed method is called if the expected exception
 is not thrown.
            TestFailed()

        Catch e As Exception

            Console.WriteLine(("An exception was thrown because
 of an open demand: " + e.Message))
        End Try
    End Sub 'DenyAllTestMethod

    Public Shared Sub TestFailed()
        Console.WriteLine("Executing TestFailed.")
        Console.WriteLine("Throwing an exception.")
        Throw New Exception()
    End Sub 'TestFailed

    Overloads Shared Sub
 Main(ByVal args() As String)
        FileDialogPermissionAttributeDemo()
    End Sub 'Main
End Class '[MyClass] 
// This sample demonstrates the use of the FileDialogPermissionAttribute.
using System;
using System.Reflection;
using System.Security.Permissions;
using System.Security;
using System.IO;

    class MyClass
    {
        public static void
 FileDialogPermissionAttributeDemo()
        {  
            try
            {
                PermitOnlyMethod();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
            try
            {
                DenyMethod();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
            try
            {
                DenyAllMethod();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }

        }

        // This method demonstrates PermitOnly with the Open property
 set to true.
        [FileDialogPermissionAttribute(SecurityAction.PermitOnly, Open = true)]
        public static void
 PermitOnlyMethod()
        {
            Console.WriteLine("Executing PermitOnlyMethod.");
            Console.WriteLine("PermitOnly the Open permission.");
            PermitOnlyTest();

        }
    
        public static void
 PermitOnlyTest()
        {
            Console.WriteLine("Executing PermitOnlyTest.");
            try
            {
                PermissionSet ps = new PermissionSet(PermissionState.None);
                ps.AddPermission(
                    new FileDialogPermission(FileDialogPermissionAccess.Open));
                Console.WriteLine("Demanding permission to open a file.");
                ps.Demand();
                Console.WriteLine("Demand succeeded.");
                ps.AddPermission(
                    new FileDialogPermission(FileDialogPermissionAccess.Save));
                Console.WriteLine("Demanding permission to save a file.");
                // This demand should cause an exception.
                ps.Demand();
                // The TestFailed method is called if an exception is
 not thrown.
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception was thrown because of a save
 demand: " + e.Message);
            }
        }

        // Set the Save property for a Deny action.
        [FileDialogPermissionAttribute(SecurityAction.Deny, Save = true)]

        public static void
 DenyMethod()
        {
            Console.WriteLine("Executing DenyMethod.");
            Console.WriteLine("Denying the Save permission.");
            DenyTest();
        }

        public static void
 DenyTest()
        {
            Console.WriteLine("Executing DenyTest.");
            try
            {
                PermissionSet ps = new PermissionSet(PermissionState.None);
                ps.AddPermission(
                    new FileDialogPermission(FileDialogPermissionAccess.Open));
                Console.WriteLine("Demanding permission to open a file.");
                ps.Demand();
                Console.WriteLine("Demand succeeded.");
                ps.AddPermission(
                    new FileDialogPermission(FileDialogPermissionAccess.Save));
                Console.WriteLine("Demanding permission to save a file.");
                // This demand should cause an exception.
                ps.Demand();
                // The TestFailed method is called if an exception is
 not thrown.
                TestFailed();
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception was thrown because of an open
 demand: " + e.Message);
            }
        }

        // This method demonstrates the use of the FileDialogPermissionAttribute
 to deny all permissions.
        [FileDialogPermissionAttribute(SecurityAction.Deny, Unrestricted = true)]
        public static void
 DenyAllMethod()
        {
            Console.WriteLine("Executing DenyAllMethod.");
            Console.WriteLine("Denied all FileDialogPermissions");

            DenyAllTestMethod();
        }
        // This method tests to assure permissions have been denied.
        public static void
 DenyAllTestMethod()
        {
            Console.WriteLine("Executing DenyAllTestMethod.");
            try
            {
                PermissionSet ps = new PermissionSet(PermissionState.None);
                ps.AddPermission(
                new FileDialogPermission(FileDialogPermissionAccess.Open));
                Console.WriteLine("Demanding permission to open a file.");
                // This demand should cause an exception.
                ps.Demand();
                // The TestFailed method is called if the expected exception
 is not thrown.
                TestFailed();
            }

            catch (Exception e)

            {
                Console.WriteLine("An exception was thrown because of an open
 demand: " + e.Message);
            }
        }
        public static void
 TestFailed()
        {
            Console.WriteLine("Executing TestFailed.");
            Console.WriteLine("Throwing an exception.");
            throw new Exception();
        }

        static void Main(string[]
 args)
        {
            FileDialogPermissionAttributeDemo();
        }

    }
// This sample demonstrates the use of the FileDialogPermissionAttribute.
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Runtime::InteropServices;
using namespace System::Security;
using namespace System::IO;
void PermitOnlyTest()
{
   Console::WriteLine( "Executing PermitOnlyTest." );
   try
   {
      PermissionSet^ ps = gcnew PermissionSet( PermissionState::None );
      ps->AddPermission( gcnew FileDialogPermission( FileDialogPermissionAccess::Open
 ) );
      Console::WriteLine( "Demanding permission to open a file." );
      ps->Demand();
      Console::WriteLine( "Demand succeeded." );
      ps->AddPermission( gcnew FileDialogPermission( FileDialogPermissionAccess::Save
 ) );
      Console::WriteLine( "Demanding permission to save a file." );
      
      // This demand should cause an exception.
      ps->Demand();
      
      // The TestFailed method is called if an exception is not thrown.
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "An exception was thrown because of a save demand:
 {0}", e->Message );
   }

}


// This method demonstrates PermitOnly with the Open property set to
 true.

[FileDialogPermissionAttribute(SecurityAction::PermitOnly,Open=true)]
void PermitOnlyMethod()
{
   Console::WriteLine( "Executing PermitOnlyMethod." );
   Console::WriteLine( "PermitOnly the Open permission." );
   PermitOnlyTest();
}


void TestFailed()
{
   Console::WriteLine( "Executing TestFailed." );
   Console::WriteLine( "Throwing an exception." );
   throw gcnew Exception;
}

void DenyTest()
{
   Console::WriteLine( "Executing DenyTest." );
   try
   {
      PermissionSet^ ps = gcnew PermissionSet( PermissionState::None );
      ps->AddPermission( gcnew FileDialogPermission( FileDialogPermissionAccess::Open
 ) );
      Console::WriteLine( "Demanding permission to open a file." );
      ps->Demand();
      Console::WriteLine( "Demand succeeded." );
      ps->AddPermission( gcnew FileDialogPermission( FileDialogPermissionAccess::Save
 ) );
      Console::WriteLine( "Demanding permission to save a file." );
      
      // This demand should cause an exception.
      ps->Demand();
      
      // The TestFailed method is called if an exception is not thrown.
      TestFailed();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "An exception was thrown because of an open demand:
 {0}", e->Message );
   }

}


// Set the Save property for a Deny action.

[FileDialogPermissionAttribute(SecurityAction::Deny,Save=true)]
void DenyMethod()
{
   Console::WriteLine( "Executing DenyMethod." );
   Console::WriteLine( "Denying the Save permission." );
   DenyTest();
}


// This method tests to assure permissions have been denied.
void DenyAllTestMethod()
{
   Console::WriteLine( "Executing DenyAllTestMethod." );
   try
   {
      PermissionSet^ ps = gcnew PermissionSet( PermissionState::None );
      ps->AddPermission( gcnew FileDialogPermission( FileDialogPermissionAccess::Open
 ) );
      Console::WriteLine( "Demanding permission to open a file." );
      
      // This demand should cause an exception.
      ps->Demand();
      
      // The TestFailed method is called if the expected exception is
 not thrown.
      TestFailed();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "An exception was thrown because of an open demand:
 {0}", e->Message );
   }

}


// This method demonstrates the use of the FileDialogPermissionAttribute
 to deny all permissions.

[FileDialogPermissionAttribute(SecurityAction::Deny,Unrestricted=true)]
void DenyAllMethod()
{
   Console::WriteLine( "Executing DenyAllMethod." );
   Console::WriteLine( "Denied all FileDialogPermissions" );
   DenyAllTestMethod();
}

void FileDialogPermissionAttributeDemo()
{
   try
   {
      PermitOnlyMethod();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

   try
   {
      DenyMethod();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

   try
   {
      DenyAllMethod();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}

int main()
{
   FileDialogPermissionAttributeDemo();
}

// This sample demonstrates the use of the FileDialogPermissionAttribute.
import System.*;
import System.Reflection.*;
import System.Security.Permissions.*;
import System.Security.*;
import System.IO.*;

class MyClass
{
    public static void FileDialogPermissionAttributeDemo()
    {
        try {
            PermitOnlyMethod();
        }
        catch (System.Exception e) {
            Console.WriteLine(e.get_Message().toString());
        }
        try {
            DenyMethod();
        }
        catch (System.Exception e) {
            Console.WriteLine(e.get_Message().toString());
        }
        try {
            DenyAllMethod();
        }
        catch (System.Exception e) {
            Console.WriteLine(e.get_Message().toString());
        }
    } //FileDialogPermissionAttributeDemo

    // This method demonstrates PermitOnly with the Open property set to
 true.
    /** @attribute FileDialogPermissionAttribute(SecurityAction.PermitOnly, 
        Open = true)
     */
    public static void PermitOnlyMethod()
    {
        Console.WriteLine("Executing PermitOnlyMethod.");
        Console.WriteLine("PermitOnly the Open permission.");
        PermitOnlyTest();
    } //PermitOnlyMethod

    public static void PermitOnlyTest()
    {
        Console.WriteLine("Executing PermitOnlyTest.");
        try {
            PermissionSet ps = new PermissionSet(PermissionState.None);
            ps.AddPermission(new FileDialogPermission(
                FileDialogPermissionAccess.Open));
            Console.WriteLine("Demanding permission to open a file.");
            ps.Demand();
            Console.WriteLine("Demand succeeded.");
            ps.AddPermission(new FileDialogPermission(
                FileDialogPermissionAccess.Save));
            Console.WriteLine("Demanding permission to save a file.");

            // This demand should cause an exception.
            ps.Demand();
        } // The TestFailed method is called if an exception is not
 thrown.
        catch (System.Exception e) {
            Console.WriteLine(("An exception was thrown because " 
                + "of a save demand: " + e.get_Message()));
        }
    } //PermitOnlyTest

    // Set the Save property for a Deny action.
    /** @attribute FileDialogPermissionAttribute(SecurityAction.Deny, 
        Save = true)
     */
    public static void DenyMethod()
    {
        Console.WriteLine("Executing DenyMethod.");
        Console.WriteLine("Denying the Save permission.");
        DenyTest();
    } //DenyMethod

    public static void DenyTest()
    {
        Console.WriteLine("Executing DenyTest.");
        try {
            PermissionSet ps = new PermissionSet(PermissionState.None);
            ps.AddPermission(new FileDialogPermission(
                FileDialogPermissionAccess.Open));
            Console.WriteLine("Demanding permission to open a file.");
            ps.Demand();
            Console.WriteLine("Demand succeeded.");
            ps.AddPermission(new FileDialogPermission(
                FileDialogPermissionAccess.Save));
            Console.WriteLine("Demanding permission to save a file.");

            // This demand should cause an exception.
            ps.Demand();

            // The TestFailed method is called if an exception is not
 thrown.
            TestFailed();
        }
        catch (System.Exception e) {
            Console.WriteLine(("An exception was thrown because " 
                + "of an open demand: " + e.get_Message()));
        }
    } //DenyTest  

    // This method demonstrates the use of the FileDialogPermissionAttribute
    //to deny all permissions.
    /** @attribute FileDialogPermissionAttribute(SecurityAction.Deny, 
        Unrestricted = true)
     */
    public static void DenyAllMethod()
    {
        Console.WriteLine("Executing DenyAllMethod.");
        Console.WriteLine("Denied all FileDialogPermissions");
        DenyAllTestMethod();
    } //DenyAllMethod

    // This method tests to assure permissions have been denied.
    public static void DenyAllTestMethod()
    {
        Console.WriteLine("Executing DenyAllTestMethod.");
        try {
            PermissionSet ps = new PermissionSet(PermissionState.None);
            ps.AddPermission(new FileDialogPermission(
                FileDialogPermissionAccess.Open));
            Console.WriteLine("Demanding permission to open a file.");

            // This demand should cause an exception.
            ps.Demand();

            // The TestFailed method is called if the expected exception
 is       
            //not thrown.
            TestFailed();
        }
        catch (System.Exception e) {
            Console.WriteLine(("An exception was thrown because " 
                + "of an open demand: " + e.get_Message()));
        }
    } //DenyAllTestMethod

    public static void TestFailed()
 throws Exception
    {
        Console.WriteLine("Executing TestFailed.");
        Console.WriteLine("Throwing an exception.");
        throw new Exception();
    } //TestFailed

    public static void main(String[]
 args)
    {
        FileDialogPermissionAttributeDemo();
    } //main
} //MyClass 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FileDialogPermissionAttribute クラス
FileDialogPermissionAttribute メンバ
System.Security.Permissions 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からFileDialogPermissionAttribute コンストラクタを検索した結果を表示しています。
Weblioに収録されているすべての辞書からFileDialogPermissionAttribute コンストラクタを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からFileDialogPermissionAttribute コンストラクタ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「FileDialogPermissionAttribute コンストラクタ」の関連用語

FileDialogPermissionAttribute コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FileDialogPermissionAttribute コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS