StorageFolder.CreateFileAsync 메서드

정의

오버로드

CreateFileAsync(String)

현재 폴더에 지정된 이름의 새 파일을 만듭니다.

CreateFileAsync(String, CreationCollisionOption)

현재 폴더에 새 파일을 만듭니다. 또한 이 메서드는 이름이 같은 파일이 현재 폴더에 이미 있는 경우 수행할 작업을 지정합니다.

CreateFileAsync(String)

현재 폴더에 지정된 이름의 새 파일을 만듭니다.

public:
 virtual IAsyncOperation<StorageFile ^> ^ CreateFileAsync(Platform::String ^ desiredName) = CreateFileAsync;
/// [Windows.Foundation.Metadata.Overload("CreateFileAsyncOverloadDefaultOptions")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<StorageFile> CreateFileAsync(winrt::hstring const& desiredName);
[Windows.Foundation.Metadata.Overload("CreateFileAsyncOverloadDefaultOptions")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<StorageFile> CreateFileAsync(string desiredName);
function createFileAsync(desiredName)
Public Function CreateFileAsync (desiredName As String) As IAsyncOperation(Of StorageFile)

매개 변수

desiredName
String

Platform::String

winrt::hstring

현재 폴더에서 만들 새 파일의 이름입니다.

반환

이 메서드가 완료되면 새 파일을 나타내는 StorageFile 을 반환합니다.

구현

M:Windows.Storage.IStorageFolder.CreateFileAsync(System.String) M:Windows.Storage.IStorageFolder.CreateFileAsync(Platform::String) M:Windows.Storage.IStorageFolder.CreateFileAsync(winrt::hstring)
특성

예외

파일 이름에 잘못된 문자가 포함되어 있거나 파일 이름의 형식이 올바르지 않습니다. desiredName 값을 확인합니다.

현재 폴더에 파일을 만들 수 있는 권한이 없습니다.

예제

다음 예제에서는 CreateFileAsync(String, CreationCollisionOption) 오버로드된 메서드를 호출하여 현재 폴더에 새 파일을 만드는 방법을 보여 줍니다. 다음은 지정한 desiredName 파일이 현재 폴더에 이미 있는 경우 작업이 실패하는 옵션 값을 명시적으로 지정하는 예제입니다.

using Windows.Storage;
using System.Threading.Tasks;

// Get the app's local folder.
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

// Create a new file in the current folder.
// Raise an exception if the file already exists.
string desiredName = "test.txt";
StorageFile newFile = await localFolder.CreateFileAsync(desiredName, CreationCollisionOption.FailIfExists);
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Gets the app's local folder.
    Windows::Storage::StorageFolder localFolder{ Windows::Storage::ApplicationData::Current().LocalFolder() };

    // Create a new file in the current folder, and throw an exception if the file already exists.
    std::wstring desiredName{ L"test.txt" };
    StorageFile newFile{ co_await localFolder.CreateFileAsync(desiredName, Windows::Storage::CreationCollisionOption::FailIfExists) };
    // Do something with the new file.
}
//Gets the app's local folder
StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;

//Create a new file in the current folder
// Raise an exception if the file already exists
String^ desiredName = "test.txt";
auto createFileTask = create_task(localFolder->CreateFileAsync(desiredName, Windows::Storage::CreationCollisionOption::FailIfExists));
createFileTask.then([](StorageFile^ newFile)
{
  //Do something with the new file.
 });

설명

이 메서드는 기본적으로 CreationCollisionOption 열거형의 FailIfExists 값을 사용합니다. 즉, 이 메서드는 이름이 같은 파일이 현재 폴더에 이미 있는 경우 예외를 발생합니다. 파일 이름 충돌을 다른 방식으로 처리하려면 CreateFileAsync(String, CreationCollisionOption) 메서드를 호출합니다.

라이브러리와 같은 가상 폴더 또는 파일 그룹의 컨테이너를 나타내는 폴더(예: GetFoldersAsync 메서드의 일부 오버로드에서 반환 값)를 만들려는 경우 CreateFileAsync 메서드가 실패할 수 있습니다.

추가 정보

적용 대상

CreateFileAsync(String, CreationCollisionOption)

현재 폴더에 새 파일을 만듭니다. 또한 이 메서드는 이름이 같은 파일이 현재 폴더에 이미 있는 경우 수행할 작업을 지정합니다.

public:
 virtual IAsyncOperation<StorageFile ^> ^ CreateFileAsync(Platform::String ^ desiredName, CreationCollisionOption options) = CreateFileAsync;
/// [Windows.Foundation.Metadata.Overload("CreateFileAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<StorageFile> CreateFileAsync(winrt::hstring const& desiredName, CreationCollisionOption const& options);
[Windows.Foundation.Metadata.Overload("CreateFileAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<StorageFile> CreateFileAsync(string desiredName, CreationCollisionOption options);
function createFileAsync(desiredName, options)
Public Function CreateFileAsync (desiredName As String, options As CreationCollisionOption) As IAsyncOperation(Of StorageFile)

매개 변수

desiredName
String

Platform::String

winrt::hstring

현재 폴더에서 만들 새 파일의 이름입니다.

options
CreationCollisionOption

지정된 desiredName 파일이 현재 폴더에 이미 있는 경우 충돌을 처리하는 방법을 결정하는 열거형 값 중 하나입니다.

반환

이 메서드가 완료되면 새 파일을 나타내는 StorageFile 을 반환합니다.

구현

M:Windows.Storage.IStorageFolder.CreateFileAsync(System.String,Windows.Storage.CreationCollisionOption) M:Windows.Storage.IStorageFolder.CreateFileAsync(Platform::String,Windows.Storage.CreationCollisionOption) M:Windows.Storage.IStorageFolder.CreateFileAsync(winrt::hstring,Windows.Storage.CreationCollisionOption)
특성

예외

CreationCollisionOption.FailIfExists를 지정했으며 desiredName이 지정된 파일이 현재 폴더에 이미 있습니다.

파일 이름의 형식이 잘못되었습니다. desiredName 값을 확인합니다.

현재 폴더에 파일을 만들 수 있는 권한이 없습니다.

추가 정보

적용 대상