IsolatedStorageFile::CreateDirectory Method

Creates a directory in the isolated storage scope.

Namespace:  System.IO.IsolatedStorage
Assembly:  mscorlib (in mscorlib.dll)

void CreateDirectory(
	String^ dir


Type: System::String

The relative path of the directory to create within the isolated storage scope.


The current code has insufficient permissions to create isolated storage directory.


The directory path is nullptr.

The created directory initially contains no files. If the directory already exists, the CreateDirectory method returns without creating a new directory. The How to: Create Files and Directories in Isolated Storage example demonstrates the use of the CreateDirectory method

The following code example demonstrates the CreateDirectory method. For the complete context of this example, see the IsolatedStorageFile overview.

double SetNewPrefsForUser()
      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" );

            // 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." );

               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.

      // 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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft