WP7 IsolatedStorageFileStream Error “Operation not permitted on IsolatedStorageFileStream”
-
27-06-2021 - |
Question
I'm trying to open a txt file that's saved as content in my app, however I run into the error shown in the thread's title. Here's the line of code giving me trouble:
var readStream = new IsolatedStorageFileStream(mapFileName, FileMode.Open, store);
which is used when a the method
map.loadMap(string mapFileName)
is called.
Any help would be greatly appreciated.
EDIT
I've created a new method to read in the text file using an IsolatedStorageFile and IsolatedFileStream however I'm completely clueless on how I would go about reading in the data to a 2D int array, using my old parsing code and a screenshot of my map01.txt for reference could anyone suggest a way of going about this as I have not found any relevant documentation on-line:
int x = 0, y = 0;
var store = IsolatedStorageFile.GetUserStoreForApplication();
var readStream = new IsolatedStorageFileStream(mapFileName, FileMode.Open, store);
var stream = new StreamReader(readStream);
do
{
string line = stream.ReadLine();
string[] numbers = line.Split(',');
foreach (string e in numbers)
{
int tile = int.Parse(e);
this.tileID[x,y] = tile;
x++;
}
y++;
}
while (!stream.EndOfStream);`
Thanks!
Solution
You don't use IsolatedStorage for project files, they are for files that are stored in the cache/appdata, you actually read them like a normal file.
Go to: http://msdn.microsoft.com/en-us/library/bb199073.aspx
To learn how to open/read/save files.