Search code examples
c#windows-runtimetext-filesembedded-resource

Using embedded text files in a rt app


this might be a stupid question, but I just can't seem to figure out how to access my text files that I embedded in my app. I know several ways to do it for desktop apps (through searching for ways to do it for rt apps) but have never found a way to do it for rt apps. This has been bugging me for MONTHS!


Solution

  • Anything in your app package can be referred to using an ms-appx:/// URI (the three /// are important), and opened with StorageFile.GetFromApplicationUriAsync (a static method, see http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.getfilefromapplicationuriasync.aspx).

    You can also get your package's StorageFolder object through Windows.ApplicationModel.Package.InstalledLocation, see http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.package.installedlocation.aspx. Then you use StorageFolder.GetFileAsync (http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefolder.getfileasync.aspx) with a relative pathname.