IsolatedStorageFile.CreateDirectory メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > IsolatedStorageFile.CreateDirectory メソッドの意味・解説 

IsolatedStorageFile.CreateDirectory メソッド

分離ストレージスコープ内にディレクトリ作成します

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

Public Sub CreateDirectory ( _
    dir As String _
)
Dim instance As IsolatedStorageFile
Dim dir As String

instance.CreateDirectory(dir)
public void CreateDirectory (
    string dir
)
public:
void CreateDirectory (
    String^ dir
)
public void CreateDirectory (
    String dir
)
public function CreateDirectory (
    dir : String
)

パラメータ

dir

分離ストレージスコープ内に作成するディレクトリ相対パス

例外例外
例外種類条件

IsolatedStorageException

現在のコードには、分離ストレージ ディレクトリ作成するためのアクセス許可不足してます。

ArgumentNullException

ディレクトリパスnull 参照 (Visual Basic では Nothing) です。

解説解説

作成されるディレクトリには、初期状態ではファイル含まれていません。CreateDirectory メソッド使用方法については、「ファイルおよびディレクトリ作成」の例を参照してください

使用例使用例

CreateDirectory メソッドコード例次に示します。この例のコンテキスト全体については、IsolatedStorageFile の概要参照してください

Public Function SetNewPrefsForUser() As
 Double
    Try
        Dim inputChar As Byte
        Dim isoFile As IsolatedStorageFile
 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
 IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))

        ' If this is not a new user, archive the old preferences and
 
        ' overwrite them using the new preferences.
        If Not Me.myNewPrefs
 Then
            If isoFile.GetDirectoryNames("Archive").Length
 = 0 Then
                isoFile.CreateDirectory("Archive")
            Else

                Dim source As New
 IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate,
 isoFile)
                Dim canWrite, canRead As Boolean
                ' This is the stream from which data will be read.
                If source.CanRead Then canRead
 = True Else canRead = False
                Console.WriteLine("Is the source file readable?
 " & canRead)
                Console.WriteLine("Creating new IsolatedStorageFileStream
 for Archive.")
                ' Open or create a writable file.
                Dim target As New
 IsolatedStorageFileStream("Archive\ " & Me.userName,
 _
                     FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoFile)
                ' This is the stream to which data will be written.
                If target.CanWrite Then canWrite
 = True Else canWrite = False
                Console.WriteLine("Is the target file writable?
 " & canWrite)
                target.SetLength(0)  'rewind the target file

                ' Stream the old file to a new file in the Archive directory.
                If source.IsAsync And target.IsAsync
 Then
                    ' IsolatedStorageFileStreams cannot be asynchronous.
  However, you
                    ' can use the asynchronous BeginRead and BeginWrite
 functions
                    ' with some possible performance penalty.
                    Console.WriteLine("IsolatedStorageFileStreams
 cannot be asynchronous.")
                Else
                    Console.WriteLine("Writing data to the new
 file.")
                    While source.Position < source.Length
                        inputChar = CByte(source.ReadByte())
                        target.WriteByte(inputChar)
                    End While

                    ' Determine the size of the IsolatedStorageFileStream
                    ' by checking its Length property.
                    Console.WriteLine(("Total Bytes Read: "
 & source.Length))
                End If

                ' After you have read and written to the streams, close
 them.    
                target.Close()
                source.Close()
            End If
        End If
        ' Open or create a writable file with a maximum size of 10K.
        Dim isoStream As New
 IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate,
 _
            FileAccess.Write, FileShare.Write, 10240, isoFile)
        isoStream.SetLength(0) 'Position to overwrite the old data.
public double SetNewPrefsForUser()
{
    try
    {
        byte inputChar;
        IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User
 |
            IsolatedStorageScope.Assembly |
            IsolatedStorageScope.Domain,
            typeof(System.Security.Policy.Url),
            typeof(System.Security.Policy.Url));

        // If this is not a new user, archive the old preferences and
 
        // overwrite them using the new preferences.
        if (!this.myNewPrefs)
        {
            if (isoFile.GetDirectoryNames("Archive").Length
 == 0)
                isoFile.CreateDirectory("Archive");
            else
            {

                IsolatedStorageFileStream source =
                    new IsolatedStorageFileStream(this.userName
,
 FileMode.OpenOrCreate,
                    isoFile);
                // This is the stream from which data will be read.
                Console.WriteLine("Is the source file readable? " + (source.CanRead
 ? "true" : "false"));
                Console.WriteLine("Creating new IsolatedStorageFileStream
 for Archive.");

                // Open or create a writable file.
                IsolatedStorageFileStream target =
                    new IsolatedStorageFileStream("Archive\\
 " + this.userName,
                    FileMode.OpenOrCreate,
                    FileAccess.Write,
                    FileShare.Write,
                    isoFile);
                Console.WriteLine("Is the target file writable? " + (target.CanWrite
 ? "true" : "false"));
                // Stream the old file to a new file in the Archive
 directory.
                if (source.IsAsync && target.IsAsync)
                {
                    // IsolatedStorageFileStreams cannot be asynchronous.
  However, you
                    // can use the asynchronous BeginRead and BeginWrite
 functions
                    // with some possible performance penalty.

                    Console.WriteLine("IsolatedStorageFileStreams cannot be
 asynchronous.");
                }

                else
                {
                    Console.WriteLine("Writing data to the new
 file.");
                    while (source.Position < source.Length)
                    {
                        inputChar = (byte)source.ReadByte();
                        target.WriteByte(inputChar);
                    }

                    // Determine the size of the IsolatedStorageFileStream
                    // by checking its Length property.
                    Console.WriteLine("Total Bytes Read: " + source.Length);

                }

                // After you have read and written to the streams, close
 them.
                target.Close();
                source.Close();
            }
        }

        // Open or create a writable file with a maximum size of 10K.
        IsolatedStorageFileStream isoStream =
            new IsolatedStorageFileStream(this.userName
,
            FileMode.OpenOrCreate,
            FileAccess.Write,
            FileShare.Write,
            10240,
            isoFile);
        isoStream.Position = 0;  // Position to overwrite the old data.
double SetNewPrefsForUser()
{
   try
   {
      Byte inputChar;
      IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetStore( static_cast<IsolatedStorageScope>(IsolatedStorageScope::User
 | IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain), System::Security::Policy::Url::typeid,
 System::Security::Policy::Url::typeid );
      
      // If this is not a new user, archive the old preferences and
 
      // overwrite them using the new preferences.
      if (  !this->NewPrefs )
      {
         if ( isoFile->GetDirectoryNames( "Archive"
 )->Length == 0 )
                     isoFile->CreateDirectory( "Archive" );
         else
         {
            
            // This is the stream to which data will be written.
            IsolatedStorageFileStream^ source = gcnew IsolatedStorageFileStream(
 this->userName,FileMode::OpenOrCreate,isoFile );
            
            // This is the stream from which data will be read.
            Console::WriteLine( "Is the source file readable?  {0}", (source->CanRead
 ? (String^)"true" : "false")
 );
            Console::WriteLine( "Creating new IsolatedStorageFileStream
 for Archive." );
            
            // Open or create a writable file.
            IsolatedStorageFileStream^ target = gcnew IsolatedStorageFileStream(
 String::Concat("Archive\\",this->userName),FileMode::OpenOrCreate,FileAccess::Write,FileShare::Write,isoFile
 );
            
            Console::WriteLine( "Is the target file writable? {0}", (target->CanWrite
 ? (String^)"true" : "false")
 );
            
            // Stream the old file to a new file in the Archive directory.
            if ( source->IsAsync && target->IsAsync
 )
            {
               
               // IsolatedStorageFileStreams cannot be asynchronous.
  However, you
               // can use the asynchronous BeginRead and BeginWrite
 functions
               // with some possible performance penalty.
               Console::WriteLine( "IsolatedStorageFileStreams cannot be asynchronous."
 );
            }
            else
            {
               
               Console::WriteLine( "Writing data to the new
 file." );
               while ( source->Position < source->Length
 )
               {
                  inputChar = (Byte)source->ReadByte();
                  target->WriteByte( (Byte)source->ReadByte() );
               }
               
               // Determine the size of the IsolatedStorageFileStream
               // by checking its Length property.
               Console::WriteLine( "Total Bytes Read: {0}", source->Length.ToString()
 );
               
            }
            
            // After you have read and written to the streams, close
 them.
            target->Close();
            source->Close();
         }
      }
      
      // Open or create a writable file, no larger than 10k
      IsolatedStorageFileStream^ isoStream = gcnew IsolatedStorageFileStream( this->userName,FileMode::OpenOrCreate,FileAccess::Write,FileShare::Write,10240,isoFile
 );
      
      isoStream->Position = 0; // Position to overwrite the old data.
      
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IsolatedStorageFile クラス
IsolatedStorageFile メンバ
System.IO.IsolatedStorage 名前空間



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

辞書ショートカット

すべての辞書の索引

IsolatedStorageFile.CreateDirectory メソッドのお隣キーワード
検索ランキング

   

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



IsolatedStorageFile.CreateDirectory メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS