Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 128k

how to save data in xml using windows 8.1 mobile app

Aug 12 2016 6:57 AM
when i click save button data is not saving in xml file
 
 
Here is the code:
 
 private const string XmlFile = "Order.xml";
private async void btncalculate_Click(object sender, RoutedEventArgs e)
{
ClsOrder ord = new ClsOrder();
ord.Id = 1;
ord.package = str;
ord.Domestic = strchk;
List<ClsOrder> ordlist = await getXmlorderlist();
ordlist.Add(ord);
using (var stream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(XmlFile, CreationCollisionOption.ReplaceExisting))
{
var serializer = new DataContractSerializer(typeof(List<ClsOrder>));
serializer.WriteObject(stream, ordlist);
}
}
private async Task<List<ClsOrder>> getXmlorderlist()
{
await ApplicationData.Current.LocalFolder.CreateFileAsync(XmlFile, CreationCollisionOption.OpenIfExists);
var stream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(XmlFile);
if (stream.Length == 0)
return new List<ClsOrder>();
DataContractSerializer serializer = new DataContractSerializer(typeof(List<ClsOrder>));
List<ClsOrder> ordlist = (List<ClsOrder>)serializer.ReadObject(stream);
return ordlist;
}
 
 
How to save data in xml file.?? This code is not working.. I have taken all the data in list List<ClsOrder> ordlist,I want to save data in xml.

Answers (2)