Windows phone 7 检索图像时不允许对IsolatedStorageFileStream执行操作

Windows phone 7 检索图像时不允许对IsolatedStorageFileStream执行操作,windows-phone-7,Windows Phone 7,我不明白为什么只有硬代码文件名才有效 1) Without hardcoding filename . Problems: Operation not permitted on IsolatedStorageFileStream 2) But when I hardcode the filename, say, "Test.jpg" in SaveImageFile() and GetImageInISO(), I can view the image and there is

我不明白为什么只有硬代码文件名才有效

1) Without hardcoding filename . Problems: Operation not permitted on IsolatedStorageFileStream 2) But when I hardcode the filename, say, "Test.jpg" in SaveImageFile() and GetImageInISO(), I can view the image and there is no error message. 1---------- save an Image from ImageControl : Private void SaveImageFile() { string strImgFile = strCountry + strCity + ".jpg"; using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(strImgFile, FileMode.Create, store)) { WriteableBitmap wb = new WriteableBitmap(g_IntWidth, g_IntHeight); wb.Render(cn, new TranslateTransform()); wb.Invalidate(); System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, isfs, g_IntWidth, g_IntHeight, 0, 100); isfs.Close(); } } } --2------------Read the image private void GetImageInISO() { string strPassIn = strCountryName + strCityName + ".jpg"; BitmapImage bmp = new BitmapImage(); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream isfs = store.OpenFile(strPassIn, System.IO.FileMode.Open,FileAccess.Read)) { if (isfs.Length > 0) { bmp.SetSource(isfs); isfs.Close(); } else { MessageBox.Show("Empty file"); } } } image1.Width = bmp.PixelWidth; image1.Height = bmp.PixelHeight; image1.Source = bmp; } }
谢谢大家。你的建议很有帮助。文件名包含不应包含的空格字符。删除空格后,它就可以工作。

这种错误通常是由于使用另一段代码试图检索的文件的其他原因造成的。另外,最后3行代码不包括未设置bmp对象的情况,请尝试将这些代码包装到ifbmp!=null{}子句。我猜这是线程的b/c,您遇到了这个问题b/c您的UI类似于一个国家和城市列表,每个国家和城市都有一个不同的图像,可以通过此方法同时检索。正当你应该把你的钥匙锁上statement@Eugene当前位置我尝试了所有可能的方法。结果是一样的。处理硬代码文件名而不是bmp问题。如果您可以发布显示如何在前端保存/检索数据的代码,可能会有所帮助。另外,请检查以绝对确保您请求的文件名确实存在于隔离存储中。