How to access file inside of IsolatedStorageFileSt

2019-08-11 17:45发布

问题:

In my project I want to create a xml file and save it,and then retrieve the xml file. that is my code :

XDocument doc = new XDocument(new XDeclaration("1.0", "iso-8859-1", "yes"),
                                       new XElement("checkout",
                                       new XElement("currency", "BRL"),
                                       new XElement("items",
                                       new XElement("item",
                                           new XElement("id", "0001"),
                                           new XElement("description", "Dízimo"),
                                           new XElement("amount", _amount),
                                           new XElement("quantity", "1"))),
                                          //new XElement("weight", "50"),
                                       new XElement("reference", _reference),
                                       new XElement("sender",
                                       new XElement("name", _name),
                                       new XElement("email", _email),
                                       new XElement("phone",
                                       new XElement("areacode", _areacode),
                                       new XElement("number", _number))),
                                       new XElement("shipping",
                                       new XElement("type", "1"),
                                       new XElement("address",
                                       new XElement("street", _street),
                                       new XElement("number", _numberHome),
                                       new XElement("complement", _complement),
                                       new XElement("district", _district),
                                       new XElement("postalcode", _postalcode),
                                       new XElement("city", _city),
                                       new XElement("state", _state),
                                       new XElement("country", "BRA")))));

        using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (Stream stream = storage.CreateFile(@"c:\Temp\data.xml"))
            {
                doc.Save(stream);
            }
        }

But, in another class I use to use :

 var xml = XDocument.Load("a.xml").ToString();
        var content = new StringContent(
            xml,
            Encoding.GetEncoding("ISO-8859-1"),
            "application/xml");

to read the xml file form a namePath, but now I want to read from IsolatedStorageFile, how can I transform the stream object so I can use inside of XDocument.Load(stream)