我真的对 Windows Phone 8 上的一些存储功能感到困惑。我试图将由多个应用程序共享的凭据(密码/用户)保存在本地手机存储中。从那里,用户将只能在一个应用程序中更改密码一次,并且它将为所有应用程序更改。我经历过3种可能
- 保存在外部服务器上
- 在 Medialibrary 上另存为图片
- 保存在管理凭据的新特定应用程序的独立存储中
在暴露第二种情况的这段代码中,我遇到了一个问题“System.InvalidOperationException.An unexpected error has occurred”
public static void SaveToFile(byte[] Encryptedfile, string FileName)
{
using (var mediaLibrary = new MediaLibrary())
{
using (var stream = new MemoryStream(Encryptedfile))
{
var file = string.Format(FileName, Guid.NewGuid());
stream.Seek(0, SeekOrigin.Begin);
var picture = mediaLibrary.SavePicture(file, stream); //ERROR
}
}
}
函数的调用
byte[] PasswordByte = Encoding.UTF8.GetBytes(password);
byte[] UserByte = Encoding.UTF8.GetBytes(user);
byte[] EncryptedPasswordUser = ProtectedData.Protect(PasswordByte, null);
byte[] EncryptedUser = ProtectedData.Protect(UserByte, null);
IsolatedStorageOperations.SaveToFile(EncryptedPasswordUser, "Password");
IsolatedStorageOperations.SaveToFile(EncryptedUser, "User");
如果你能给我另一种方法来将文件保存在 WP8 上的公共本地存储中,或者你能给我一个解决媒体库问题的方法,我会很高兴。
谢谢