سؤال

Namely, a file that lives here: https://dl.dropboxusercontent.com/u/19417676/snowbird_confusion.png (image linked due to lack of reputation to post directly)

Tutorials and documentation encourage the use of Windows.Storage namespace, but when when running my project and enumerating every file and folder in Windows.Storage.ApplicationData, it's revealed that nothing exists in there. Furthermore, nothing exists in the Local, Roaming or Temp folders either.

Using Windows.ApplicationModel.Package.Current.InstalledLocation gets me close, but it puts me in the ...\Debug\AppX directory. When viewing the built project structure, the actual folder containing my .rtf file lives in ...\Debug\Tales, and WinRT applications are very restrictive about walking directory structures (not to mention it probably wouldn't be portable to the Windows Phone anyway).

So, how do I access this file?

هل كانت مفيدة؟

المحلول

Figured it out. I had correctly set my .rtf file to Copy to output dir: Copy Always, but had forgotten to change its Build Action to Content.

The below code now works just fine.

StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
folder = await folder.GetFolderAsync("MyFolder");
StorageFile file= await folder.GetFileAsync("MyFile.rtf");
string rtfString = await Windows.Storage.FileIO.ReadTextAsync(file);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top