I am developing an application for Windows Phone 7. I am new to Windows Phone 7. I added an XML file to my project by right-clicking the project and choosing Add → New Item. Then I can easily load the XML file in my application using the following code
IsolatedStorageFile isfData = IsolatedStorageFile.GetUserStoreForApplication(); XDocument doc = null; IsolatedStorageFileStream isfStream = null; if (isfData.FileExists(strXMLFile)) { isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.Open, isfData); doc = XDocument.Load(isfStream); isfStream.Close(); } else { doc = XDocument.Load(strXMLFile); isfStream = new IsolatedStorageFileStream(strXMLFile, FileMode.CreateNew, isfData); doc.Save(isfStream); isfStream.Close(); }
Using the code above, I can perform a read and write operation in my XML file.
But the problem occurs when I put my XML file in a folder. My problem is this: I added one folder named "XML files" to my project, right-clicking on the project name and choosing Add → New Folder in the visual studio. Then I added the XML file to the XML Files folder by clicking on the folder and choosing Add> New Item. When I put the XML file in a folder, I cannot upload it to my application. I also tried with the following statement
isfStream = new IsolatedStorageFileStream("/XML Files/"+strXMLFile, FileMode.Open, isfData);
I get an error
doc = XDocument.Load(strXMLFile);
I get an error "I can not find the file" / XML files /A.xml in the application xap package. "What should I do? How can I upload an XML file to a folder? Is there something wrong in my code? Can you provide me with some code or a link through which I can solve the above problem?
source share