2011-09-12 4 views
1

こんにちは皆さん、 私はIsolatedStorageにいくつかのデータを保存する必要があるアプリケーションで作業しています。 私のアプリケーションが動作している間、私はファイルからデータを見ることができます。アプリケーションを閉じてアプリケーションを再起動すると、データが表示されなくなります。Windowsの電話機でxmlファイルにデータを保存する方法

public static IsolatedStorageFile isstore = IsolatedStorageFile.GetUserStoreForApplication(); 
public static IsolatedStorageFileStream xyzStrorageFileStream = new IsolatedStorageFileStream("/category.xml", System.IO.FileMode.OpenOrCreate, isstore); 


public static XDocument xmldoc = XDocument.Load("category.xml"); 
favouriteDoc.Save(rssFavouriteFileStream); 
rssFavouriteFileStream.Flush(); 

いずれかのアイデアがありますか?これを行う方法?

答えて

4

構造化データを保存するには、XMLライターまたはXMLシリアライザを使用する必要があります。

たとえばデータを保存するには:

using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("People2.xml", FileMode.Create, myIsolatedStorage)) 
    { 
     XmlWriterSettings settings = new XmlWriterSettings(); 
     settings.Indent = true; 
     using (XmlWriter writer = XmlWriter.Create(isoStream, settings)) 
     { 

      writer.WriteStartElement("p", "person", "urn:person"); 
      writer.WriteStartElement("FirstName", ""); 
      writer.WriteString("Kate"); 
      writer.WriteEndElement(); 
      writer.WriteStartElement("LastName", ""); 
      writer.WriteString("Brown"); 
      writer.WriteEndElement(); 
      writer.WriteStartElement("Age", ""); 
      writer.WriteString("25"); 
      writer.WriteEndElement(); 
      // Ends the document 
      writer.WriteEndDocument(); 
      // Write the XML to the file. 
      writer.Flush(); 
     } 
    } 
} 

はそれをリードバックするには、次の

try 
{ 
    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     IsolatedStorageFileStream isoFileStream = myIsolatedStorage.OpenFile("People2.xml", FileMode.Open); 
     using (StreamReader reader = new StreamReader(isoFileStream)) 
     { 
      this.tbx.Text = reader.ReadToEnd(); 
     } 
    } 
} 
catch 
{ } 

回答はので、すべてのクレジットはWindowsPhoneGeekに行き、this articleから取られています。また、上記の記事のヘッダーの他の例を参照してください。

関連する問題