How to access file inside of IsolatedStorageFileStream Windows phone 8.1

北城余情 提交于 2019-12-24 13:54:01

问题


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)

来源:https://stackoverflow.com/questions/34554496/how-to-access-file-inside-of-isolatedstoragefilestream-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!