0

I am newbie to Windows phone. I was successful in writing and reading a dictionary from a file. But I had stucked out in reading a nested dictionaries from a file.

  1. Main_dictionary
    1. Login(Key),dictionary(value)`
    2. Validation(Key),dictionary(Value)
  2. Main_dictionary

I need to write these values under a Common dictionary to a file and also need to read from the same file. Any help.

Thanks in Advance

Anton Sizikov
  • 9,105
  • 1
  • 28
  • 39
shanWinApp
  • 23
  • 9

2 Answers2

0

You can use the XmlSerializer as described in How to XML-serialize a dictionary. It references sample code in http://huseyint.com/2007/12/xml-serializable-generic-dictionary-tipi/ (not in English but the code is helpful).

Community
  • 1
  • 1
akton
  • 14,148
  • 3
  • 43
  • 47
0

I got the solution...........

public Dictionary FileRead(string Key) { Dictionary > FileResponse = new Dictionary>(); Dictionary ReturnDictionary = new Dictionary(); try { using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fileReader = new IsolatedStorageFileStream(DisplayMessage.Storage_Directory,FileMode.Open, FileAccess.ReadWrite, isolatedStorage)) { DataContractSerializer datacontract = new DataContractSerializer(typeof(Dictionary>)); FileResponse = (Dictionary>)datacontract.ReadObject(fileReader); ReturnDictionary = FileResponse[Key]; } } } catch (Exception ex) { } return (ReturnDictionary); }

   public void FileWrite(string Key,Dictionary<string, string> FiletoStore)
    {
       try
        {
           using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                Dictionary<string, Dictionary<string, string>> StoredDictionary = new Dictionary<string, Dictionary<string, string>>();
                if (!isolatedStorage.FileExists(DisplayMessage.Storage_Directory))
               {
                   using (IsolatedStorageFileStream IsolatedfileStream = new IsolatedStorageFileStream(DisplayMessage.Storage_Directory, FileMode.OpenOrCreate, isolatedStorage))
                   {
                        DataContractSerializer datacontract = new DataContractSerializer(typeof(Dictionary<string, Dictionary<string, string>>));
                       StoredDictionary.Add(Key, FiletoStore);
                       datacontract.WriteObject(IsolatedfileStream, StoredDictionary);
                      IsolatedfileStream.Close();
                    }
                }
               else
                {
                    using (IsolatedStorageFileStream IsolatedfileStream = new IsolatedStorageFileStream(DisplayMessage.Storage_Directory, FileMode.Open, isolatedStorage))
                    {
                        DataContractSerializer datacontract = new DataContractSerializer(typeof(Dictionary<string, Dictionary<string, string>>));
                       StoredDictionary.Add(Key, FiletoStore);
                       datacontract.WriteObject(IsolatedfileStream, StoredDictionary);
                      IsolatedfileStream.Close();
                   }
              }
           }
       }
       catch (Exception ex)
      {
       }
    }
shanWinApp
  • 23
  • 9