Read XML file fom “My documents” with metro app Windows 8

I'm having an issues with a reading xml file from "my documents" folder. I created a xml file in the folder Data inside "my documents". I have changed already the Capabilities of the app but at the XmlReader reader line, there is an exception triggered "Access to the path 'C:\Users...\Documents\DomusGest\DomusGestFile.xml' is denied."

                StorageFolder storageFolder = null;
                StorageFile storageFile = null;
                storageFolder = await KnownFolders.DocumentsLibrary.GetFolderAsync("Data");
                storageFile = await storageFolder.GetFileAsync("DataXML.xml");
                string storageFilePath = storageFile.Path;


                XmlReader reader = XmlReader.Create(storageFilePath);
                while (reader.Read())
                {
                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Apparmtment"))
                    {
                        if (reader.HasAttributes)
                            {
                                WriteXML.Text = reader.GetAttribute("name");//write on Win8 App
                            }
                    }
                }

With this same code, I can read the file if the file is located in a folder of the metro app solution.

What am I doing wrong?

Thanks

Answers


You need to go to Properties, capabilities and activate Document Library Access capability. Then you need to update the app manifest declaring what type of document you want to te able to read ".xml" in your case; this can be done from the declarations tab.

This can be done, however, bear in mind this is not the best option for neither the user or you, the developer. For the user this is unsafe and will have to accept the capability, thing that may (though I doubt it) draw back some users. On the other hand, the user may modify this XML easier (or another app) and you will have to deal with it.


Need Your Help

regex match repeated line-initial strings and delete repetitions

regex perl sublimetext2

I'm a newbie with regex and am pretty sure this question has been answered somewhere, but I haven't succeeded in tweaking what I've found to do the job. I'm working with a dictionary file with repe...

Redrawing of owner-drawn winforms combobox items

winforms combobox ownerdrawn

I need to show items in a combobox with a different background color. I also want to change what that color is depending on if the item is selected (or the mouse is on top of it), just the same way...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.