首页 新闻 会员 周边

wp7 IsolatedStorage存取数据

0
悬赏园豆:20 [已解决问题] 解决于 2012-04-16 17:24

我在IsolatedStorage对图片进行操作,

首先是判断图片存不存在,不存在的话就从网上读取

但是在取图片时抛出

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.dll

这2个异常。

请问下怎么解决?

对IsolatedStorage的操作,是不是文件名一定要存在,只要不存在就会抛错?

如果是这样的话,我又怎么对IsolatedStorage里的数据进行判断它是否存在了?

我的代码如下

View Code
 1 try
 2             {
 3                 imageFolder = "images";//wenjianjia mingcheng
 4                 var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
 5                 if (!isoFile.DirectoryExists(imageFolder))
 6                 {
 7                     isoFile.CreateDirectory(imageFolder);
 8                 }
 9                 string filePath = System.IO.Path.Combine(imageFolder, imageFileName);
10                 var imageStream = isoFile.OpenFile(
11                    filePath, FileMode.Open, FileAccess.Read);
12                 {
13                     BitmapImage imageSource = new BitmapImage();
14                     imageSource.SetSource(imageStream);
15                     imageStream.Close();
16                     imageStream.Dispose();
17                     isoFile.Dispose();
18                     return imageSource;
19                 }
20             }
21             catch (Exception e) { string str = e.Message; return null; }
txy0704的主页 txy0704 | 初学一级 | 园豆:89
提问于:2012-04-16 17:14
< >
分享
最佳答案
0
FileExists你先判斷是否存在,再操作
收获园豆:20
無限遐想 | 老鸟四级 |园豆:3740 | 2012-04-16 17:18

hehe,谢谢了呀,加了这个判断就正确了

是我太粗心了...呵呵!

txy0704 | 园豆:89 (初学一级) | 2012-04-16 17:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册