다음을 통해 공유


방법: 격리된 스토리지에 파일 및 디렉터리 만들기

격리된 저장소를 가져온 후에는 데이터를 저장할 디렉터리와 파일을 만들 수 있습니다. 저장소 내에서 파일 및 디렉터리 이름은 가상 파일 시스템의 루트와 관련하여 지정됩니다.

디렉터리를 만들려면 IsolatedStorageFile.CreateDirectory 인스턴스 메서드를 사용하십시오. 존재하지 않는 디렉터리의 하위 디렉터리를 지정하면 두 디렉터리가 모두 만들어지고 이미 존재하는 디렉터리를 지정하면 메서드가 디렉터리를 만들지 않은 채 반환되고 예외가 throw되지 않습니다. 그러나 잘못된 문자를 포함하는 디렉터리 이름을 지정하면 IsolatedStorageException 예외가 throw됩니다.

파일을 만들려면 IsolatedStorageFile.CreateFile 메서드를 사용합니다.

Windows 운영 체제에서 격리된 스토리지 파일 및 디렉터리 이름은 대/소문자를 구분하지 않습니다. 즉, ThisFile.txt라는 파일을 만든 다음 THISFILE.TXT라는 다른 파일을 만들면 한 파일만 만들어집니다. 파일 이름은 표시를 위해 원래 대소문자를 유지합니다.

격리된 스토리지 파일을 만들 때 존재하지 않는 디렉터리가 경로에 포함된 경우 IsolatedStorageException을 throw합니다.

예시

다음 코드 예제는 분리된 저장소에서 파일 및 디렉터리를 만드는 방법을 보여줍니다.

using System;
using System.IO;
using System.IO.IsolatedStorage;

public class CreatingFilesDirectories
{
    public static void Main()
    {
        using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null))
        {
            isoStore.CreateDirectory("TopLevelDirectory");
            isoStore.CreateDirectory("TopLevelDirectory/SecondLevel");
            isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory");
            Console.WriteLine("Created directories.");

            isoStore.CreateFile("InTheRoot.txt");
            Console.WriteLine("Created a new file in the root.");

            isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt");
            Console.WriteLine("Created a new file in the InsideDirectory.");
        }
    }
}
Imports System.IO
Imports System.IO.IsolatedStorage

Module Module1
    Sub Main()
        Using isoStore As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

            isoStore.CreateDirectory("TopLevelDirectory")
            isoStore.CreateDirectory("TopLevelDirectory/SecondLevel")
            isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory")
            Console.WriteLine("Created directories.")

            isoStore.CreateFile("InTheRoot.txt")
            Console.WriteLine("Created a new file in the root.")

            isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt")
            Console.WriteLine("Created a new file in the InsideDirectory.")
        End Using
    End Sub
End Module

참고 항목