开发者

Windows phone 7 silverlight string array in Isolated storage

开发者 https://www.devze.com 2023-02-20 10:42 出处:网络
I have an array of strings which I am trying to store in Isolated storage, However I 开发者_如何转开发need to store each string in the array ina new file of its own.

I have an array of strings which I am trying to store in Isolated storage, However I 开发者_如何转开发need to store each string in the array in a new file of its own. Any approach is welcomed. Thanks.


I do something similar in an app with code roughly along these lines. Though I am serializing objects in an array to json. Same rough idea though.

using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) {
  for (int i = 0; i < array.Length; i++) {
    string fileName = "file" + i.ToString() + ".dat";
    using (var stream = file.CreateFile(filename)) {
      using (var writer = new StreamWriter(stream)) {
        writer.Write(array[i]);
      }
    }
  }
}

Note this is just typed straight in, I may have a mistake in there :)


Your question is a little vauge, but here I go.

What is stopping you from just serializing each string to a file with the index as the name? For example, store stringarray[0] in a file 0.xml.

Just check whether the file exists before trying to read it.

0

精彩评论

暂无评论...
验证码 换一张
取 消