I have an instance of IMvxFileStore implementation for for Windows Phone injected into my service.
Let say I want to store settings in a file located at appsettingsuserprofilesprofile1.txt
Using the file plugin, I first call the API EnsureFolder exists, passing in the full path to my profile settings file appsettingsuserprofilesprofile1.txt to ensure that this folder has been created and does exist.
Just for sanity, I check to ensure that the folder has been created using the FolderExist API. This always returns true atleast for now.
The code looks like this:
private string GetStorageItemFileName(string filename)
{
Guard.ThrowIfNull(string.IsNullOrWhiteSpace(BaseDirectory), Messages.RepositorBackingStoreIsNull);
filename = _fileStore.PathCombine(BaseDirectory, filename);
_fileStore.EnsureFolderExists(filename);
if (_fileStore.FolderExists(filename))
{
// what do do????
}
return filename;
}
However, when I attempt to write content to the file using WriteToFile API, passing in the file name returned from the method above and some string, as follows
try
{
_fileStore.WriteFile(filename, content);
}
catch (Exception ex)
{
Logger.Error(ex);
}
, I get the following exception:
System.IO.IsolatedStorage.IsolatedStorageException was caught
HResult=-2146233264 Message=Operation not permitted on
IsolatedStorageFileStream. Source=mscorlib StackTrace:
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,
FileMode mode, FileAccess access, FileShare share, Int32 bufferSize,
IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,
FileMode mode, IsolatedStorageFile isf)
at Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore.WriteFileCommon(String
path, Action`1 streamAction)
at Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore.WriteFile(String
path, String contents)
at TrackuTransit.Core.Services.DataStore.StorageItemFileRepository.Put(String
filename, StorageItem data) InnerException:
My dev environment is setup as follows:
- Surface Pro 3
- Visual Studio 2013 Community
- Windows Phone 8.1 SDK and Simulator
- MvvmCross 3.0.0.4. (yes,, it is old and will be updated after MVP).
Before I go digging into the MvvmCross code base, anyone with ideas on what I could be doing wrong here?
See Question&Answers more detail:
os