Carlo
Carlo

Reputation: 25969

Read files in Windows Phone 7

I'm trying to open a file in Windows Phone 7, but it says it doesn't exist. Here's the code I'm trying:

IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
bool test = file.FileExists("\\ClientBin\\clubs.xml");

And in my project I added a folder called ClientBin, and the clubs.xml is in there. The clubs.xml file properties are:

Build action: Content Copy to Output Directory: Copy always

I'm not sure what I'm doing wrong. You can see what I have in this screenshot.

Thanks!

Upvotes: 1

Views: 1347

Answers (1)

indyfromoz
indyfromoz

Reputation: 3763

When you ship a file with your application, it doesn't get stored in IsolatedStorage. You need use the conventional way of opening a file that ships with the XAP -

XDocument xdoc = XDocument.Load("ClientBin/customers.xml");
var customers = from query in xdoc.Descendants("Customer")
                select new Customer
                {
                   Name = (string)query.Element("Name"),
                   Employees = (int)query.Element("Employees"),
                   Phone = (string)query.Element("Phone")
                };


// Data bind to listbox
listBox1.ItemsSource = customers;

HTH, indyfromoz

Upvotes: 6

Related Questions