I don’t see what’s the matter here:
Constructor:
IsolatedStorageFile isf;
public FileManagement()
{
isf = IsolatedStorageFile.GetUserStoreForApplication();
}
when I save files:
public bool saveCredentials(String username, String userpass)
{
bool res = false;
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("usercred.custom",
FileMode.Create, FileAccess.Write, isf));
writeFile.WriteLine(username);
writeFile.WriteLine(userpass);
res = true;
return res;
}
and when I try to read them:
public String readUsername()
{
String username = "";
IsolatedStorageFileStream fileStream = isf.OpenFile("usercred.custom", FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fileStream);
username = reader.ReadLine();
return username;
}
Reading returns null.
I try to save a file and write something into it, but it somehow doesn’t work.
You have to close your streams. Please add reader.Close(), writefile.Close() and fileStream.Close() before return and try again.