Saturday, 7 September 2013

Application.GetResourceStream can't file the file in the Uri

Application.GetResourceStream can't file the file in the Uri

I'm trying to access a .js file. The file is located inside Database
folder and named myfile.js which is just a JSON formatted text-file.
This is the code I'm using (this is run from MainPage.xaml.cs:
Uri uri = new Uri("/Database/myfile.js", UriKind.Relative);
var resource = Application.GetResourceStream(uri);
StreamReader streamReader = new StreamReader(resource.Stream);
string rawData = streamReader.ReadToEnd();
It always throw an exception of NullReferenceException because the
resource variable is null.
So, the problem is in the Uri. I tried to use:
@"/Database/myfile.js"
"/Database/myfile.js"
"/LQI;component/Database/myfile.js"
But it doesn't work. When I tried to move my file to root directory and
replace the Uri string with
@"myfile.js"
it works! But I don't want that.
I also tried to rename the extension become .txt but nothing.
Please help. Thanks!

No comments:

Post a Comment