简体   繁体   中英

Write to a text file in my project's assets folder Windows Phone 8.1

I have tried to write to a text file in my project's assets folder. The program runs without error but I couldn't see any content in the text file. Can anyone please help me?

StorageFolder asset_folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile asset_file = await asset_folder.CreateFileAsync("TextFile1.txt", CreationCollisionOption.ReplaceExisting);
using(Stream s_Asset = await asset_file.OpenStreamForWriteAsync())
{
    await s_Asset.WriteAsync(data, 0, data.Length);
}

The Build Action is also set to Content .

Let me know if I have gone wrong somewhere...

You can't write to Package.Current.InstalledLocation - it's read-only. If you want to add there something, you have to do it during production.

If you want to write some files in your app - use ApplicationData.LocalFolder .

Some more help you will also find here at MSDN .

You can't modify a package content from the application. So to write to a file you have to copy the file from the assets folder to the application's IsolatedStorage.

MSDN

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