Xaml 我想将用户输入的数据保存到一个文件中,这就是我所做的。执行解决方案,但未创建文件

Xaml 我想将用户输入的数据保存到一个文件中,这就是我所做的。执行解决方案,但未创建文件,xaml,Xaml,私有异步无效提交\u commentobject发送方,RoutedEventArgs e { 字符串输入=txtInput.Text //getting the DocumentsLibrary folder where a file is to be created and then creating the example.txt file //and storing the StorageFile object that is returned:

私有异步无效提交\u commentobject发送方,RoutedEventArgs e { 字符串输入=txtInput.Text

        //getting the DocumentsLibrary folder where a file is to be created and then creating the example.txt file 
        //and storing the StorageFile object that is returned:
        try
        {
            StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
            StorageFile sampleFile = await storageFolder.GetFileAsync("sample.txt");
            //Writing to file
        await Windows.Storage.FileIO.WriteTextAsync(sampleFile, input);
        }catch(Exception)
        {

        }





    }
您必须使用CreateFileAsync而不是GetFileAsync。如果没有空的catch块,您可能会自己意识到这一点。它捕获所有异常,但对它们不做任何处理。因此,任何潜在错误都会被忽略。