简体   繁体   中英

Where are the files created with CreateFileAsync?

When I call the following function, it should create a .txt file and write a sentence in it. It seems to execute without any errors. But I cannot find where this file is stored/located after being created. I ran a Windows Search to look for the file but nothing came up. Where is this file located? Also, what is the best folder/location to put a .txt file that the program uses? Should I put it in Solution Explorer of Visual Studio or Debug folder?

    private async void CreateFile() {
     try {
      // Create sample file, replace if exists.
      StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
      StorageFile sampleFile = await storageFolder.CreateFileAsync("sample.txt", CreationCollisionOption.ReplaceExisting);

      sampleFile = await storageFolder.GetFileAsync("sample.txt");

      await FileIO.WriteTextAsync(sampleFile, "Swift as a shadow!");
     } catch (Exception ex) {
      textBox.Text = ex.ToString();
     }
    }

You can have the code show the path:

sampleFile = await storageFolder.GetFileAsync("sample.txt");
await new MessageDialog(sampleFile.Path).ShowAsync();

On Windows 10, this will be a path like:

C:\Users\[username]\AppData\Local\Packages\[Package family name]\LocalState\sample.txt

where username is the name of the logged on user and package family name is the package family name of your application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM