FileInfo.IsReadOnly プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > FileInfo.IsReadOnly プロパティの意味・解説 

FileInfo.IsReadOnly プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

現在のファイル読み取り専用であるかどうか判断する値を取得または設定します

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

Dim instance As FileInfo
Dim value As Boolean

value = instance.IsReadOnly

instance.IsReadOnly = value
public bool IsReadOnly { get;
 set; }
/** @property */
public boolean get_IsReadOnly ()

/** @property */
public void set_IsReadOnly (boolean value)

プロパティ
現在のファイル読み取り専用場合trueそれ以外場合false

例外例外
例外種類条件

FileNotFoundException

現在の FileInfo オブジェクトが示すファイルが見つかりませんでした

IOException

ファイルを開くときに、I/O エラー発生しました

UnauthorizedAccessException

現在の FileInfo オブジェクトが示すファイル読み取り専用です。

または

この操作は、現在のプラットフォームではサポートされていません。

または

呼び出し元に必要なアクセス許可がありません。

解説解説
使用例使用例

次の例では、IsReadOnly プロパティ使用してファイル読み取り専用としてマークし次に読み書き可能ファイルとしてマークします。

Imports System
Imports System.IO



Module FileExample

    Sub Main()

        Dim FileName As String
 = "test.xml"

        ' Get the read-only value for a file.
        Dim isReadOnly As Boolean
 = IsFileReadOnly(FileName)

        ' Display wether the file is read-only.
        Console.WriteLine("The file read-only value for "
 & FileName & " is: " & isReadOnly)

        Console.WriteLine("Changing the read-only value for "
 & FileName & " to true.")

        ' Set the file to read-only.
        SetFileReadAccess(FileName, True)

        ' Get the read-only value for a file.
        isReadOnly = IsFileReadOnly(FileName)

        ' Display that the file is read-only.
        Console.WriteLine("The file read-only value for "
 & FileName & " is: " & isReadOnly)

    End Sub


    ' Sets the read-only value of a file.
    Sub SetFileReadAccess(ByVal FileName As
 String, ByVal SetReadOnly As
 Boolean)
        ' Create a new FileInfo object.
        Dim fInfo As New
 FileInfo(FileName)

        ' Set the IsReadOnly property.
        fInfo.IsReadOnly = SetReadOnly

    End Sub


    ' Returns wether a file is read-only.
    Function IsFileReadOnly(ByVal FileName
 As String) As Boolean
        ' Create a new FileInfo object.
        Dim fInfo As New
 FileInfo(FileName)

        ' Return the IsReadOnly property value.
        Return fInfo.IsReadOnly

    End Function
End Module

using System;
using System.IO;

namespace FileSystemExample
{
    class FileExample
    {
        public static void
 Main()
        {
          
            string FileName = "test.xml";

            // Get the read-only value for a file.
            bool isReadOnly = IsFileReadOnly(FileName);

            // Display wether the file is read-only.
            Console.WriteLine("The file read-only value for
 " + FileName + " is: " + isReadOnly);

            Console.WriteLine("Changing the read-only value for
 " + FileName + " to true.");

            // Set the file to read-only.
            SetFileReadAccess(FileName, true);

            // Get the read-only value for a file.
            isReadOnly = IsFileReadOnly(FileName);

            // Display that the file is read-only.
            Console.WriteLine("The file read-only value for
 " + FileName + " is: " + isReadOnly);

            Console.ReadLine();

        }

        // Sets the read-only value of a file.
        public static void
 SetFileReadAccess(string FileName, bool SetReadOnly)
        {
            // Create a new FileInfo object.
            FileInfo fInfo = new FileInfo(FileName);

            // Set the IsReadOnly property.
            fInfo.IsReadOnly = SetReadOnly;

        }

        // Returns wether a file is read-only.
        public static bool
 IsFileReadOnly(string FileName)
        {
            // Create a new FileInfo object.
            FileInfo fInfo = new FileInfo(FileName);

            // Return the IsReadOnly property value.
            return fInfo.IsReadOnly;

        }

    }
}
using namespace System;
using namespace System::IO;

namespace FileSystemExample
{
    // Sets the read-only value of a file.
    void SetFileReadAccess(String^ fileName, bool
 setReadOnly)
    {
        // Create a new FileInfo object.
        FileInfo^ fInfo = gcnew FileInfo(fileName);

        // Set the IsReadOnly property.
        fInfo->IsReadOnly = setReadOnly;
    }

    // Returns whether a file is read-only.
    bool IsFileReadOnly(String^ fileName)
    {
        // Create a new FileInfo object.
        FileInfo^ fInfo = gcnew FileInfo(fileName);

        // Return the IsReadOnly property value.
        return fInfo->IsReadOnly;
    }
}

int main()
{
    try
    {
        String^ fileName = "test.xml";

        if (File::Exists(fileName))
        {
            // Get the read-only value for a file.
            bool isReadOnly = FileSystemExample::IsFileReadOnly(fileName);

            // Display whether the file is read-only.
            Console::WriteLine("The file read-only value for
 {0} is:" +
                "{1}", fileName, isReadOnly);

            Console::WriteLine("Changing the read-only value for
 {0}" +
                " to true.", fileName);

            // Set the file to read-only.
            FileSystemExample::SetFileReadAccess(fileName, true);

            // Get the read-only value for a file.
            isReadOnly = FileSystemExample::IsFileReadOnly(fileName);

            // Display that the file is read-only.
            Console::WriteLine("The file read-only value for
 {0} is:" +
                "{1}", fileName, isReadOnly);
        }
        else
        {
            Console::WriteLine("The file {0} doesn't exist.", fileName);
        }
    }
    catch (IOException^ ex)
    {
        Console::WriteLine(ex->Message);
    }
};
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

FileInfo.IsReadOnly プロパティのお隣キーワード
検索ランキング

   

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



FileInfo.IsReadOnly プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS