开发者

Read files in Windows Phone 7

开发者 https://www.devze.com 2023-01-21 05:20 出处:网络
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:

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.Ge开发者_如何学GotUserStoreForApplication();
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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消