I'm having some trouble reading an embedded resource (text file) in windows-8, usually I use Assembly.GetExecutingAssembly()
but I can't seem to do it in this one. I'm referencing the System.Reflection namespace but it says cannot find, thinking it was possibly removed.
Any ideas?
Currently using Windows 8 Consumer Preview
Code:
Assembly readAssembly = Assembly.GetExecutingAssembly();
StreamReader streamReader = new StreamReader(readAssembly.GetManifestResourceStream("Test.txt"));
Error: System.Reflection.Assembly' does not contain a definition for 'GetExecutingAssembly'
You can open a TXT file with any text editor and most popular web browsers. In Windows, you can open a TXT file with Microsoft Notepad or Microsoft WordPad, both of which come included with Windows.
To read from a text fileUse the ReadAllText method of the My. Computer. FileSystem object to read the contents of a text file into a string, supplying the path. The following example reads the contents of test.
Use the open() function with the 'r' mode to open a text file for reading. Use the read() , readline() , or readlines() method to read a text file. Always close a file after completing reading it using the close() method or the with statement.
In WinRT the resources should be included in the package. You use Package.Current.InstalledLocation.GetFileAsync
to read the resource.
The following post has some sample code:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/d4b327e3-a8f2-4d3c-8ed7-ba2ea953d0b9
In AppStore libraries you can use following code:
Stream stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream(fileName);
Why don't you use ReadFileAsync() Method available in VS 2012. Add the text file to your project and call the async method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With