So after reading and thinking a lot I have finally got my code working on my own. First the errors that operation not permitted were raised because of my bad handling of streams.
First I changed these lines:
.
.
.
}
else
_GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin);
//This part basically only creates the file, if directory was already existing.
}
else
{
//Creates directory as well as file.
_GlobalAccessRight.CreateDirectory(_DirectoryForLogin);
_GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin);
}
To:
.
.
.
}
else
_GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin).Dispose();
//This part basically only creates the file, if directory was already existing.
}
else
{
//Creates directory as well as file.
_GlobalAccessRight.CreateDirectory(_DirectoryForLogin);
_GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin).Dispose();
}
The second mistake was this: I globally declared the IsolatedStorageFile object. After using it in my First using block:
using(_GlobalAccessRight){
//Checking if directory exists; case when user had already been logged in.
if (_GlobalAccessRight.DirectoryExists(_DirectoryForLogin))
{
. . . . It got disposed at the end of it. Therefore when I used it again in the function:
using(_GlobalAccessRight){
//I have also tried by giving the FileShare argument below.
using(IsolatedStorageFileStream WritingStreamForLoginInfo = new IsolatedStorageFileStream(_DirectoryForLogin + "\\" + _FileForLogin, FileMode.OpenOrCreate, FileAccess.ReadWrite, _GlobalAccessRight)){
using(StreamWriter WritingLoginInfo = new StreamWriter(WritingStreamForLoginInfo)){
String _LoginCredentials = "UserName: ";
. . . it threw me error stating: "Store must be open for that."
So I changed it to be this:
using(_GlobalAccessRight = IsolatedStorageFile.GetUserStoreForApplication()){
using(IsolatedStorageFileStream WritingStreamForLoginInfo = new IsolatedStorageFileStream(_DirectoryForLogin + "\\" + _FileForLogin, FileMode.OpenOrCreate, FileAccess.ReadWrite, _GlobalAccessRight)){
using(StreamWriter WritingLoginInfo = new StreamWriter(WritingStreamForLoginInfo)){
String _LoginCredentials = "UserName: ";
Thats it! Bravo! :)