Question

How can I remove 1 character off the end of a certain file in IsolatedStorage?

The code I have so far is:

var appStorage = IsolatedStorageFile.GetUserStoreForApplication();

using (var writer = new StreamWriter(appStorage.OpenFile("trailCount", FileMode.Truncate, FileAccess.Write)))
{
    writer.Write(1);
}

However It doesn't seem to work.

Thanks

Was it helpful?

Solution

If you want to remove the last character you could do the following:

writer.BaseStream.SetLength(writer.BaseStream.Length - 1);

Additionaly, when opening the file, use FileMode.Open, otherwise whole file will be truncated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top