Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using linq to xml in silverlight?

I did implement a web application(asp.net,c#) where it has couple of pages .Each page has the ability to read the values from an xml file and passes into couple of text boxes in each page.User has the ability to edit the values and save,which inturn saves the xml file.I did use the linq to xml .

I have to move to the silverlight now.so i am trying to implement the same logic in a new silverlight project.I m trying to use the linq to xml in silverlight also.But some how i am unable to read the xml file which is not in the xap file.Here is my code

 XDocument doc = Document.Load("C:\Data\Data.exe.config");
            var applicationSettings = (from x in doc.Descendants("applicationSettings")
                                       from kvpair in .Element("Data.Properties.Settings").Elements("setting")
                                       select new
                                       {
                                           Name = kvpair.Attribute("name").Value,
                                           Node = kvpair.Element("value")
                                       }).ToDictionary(x => x.Name, y => y);

            string Account  = applicationSettings["Account no"].Node.Value.ToString();
           txtAccountno.Text = AttendanceWindow;
            string Details=applicationSettings["Details"].Node.Value.ToString();
            txtDetails.Text = Details;
like image 684
Macnique Avatar asked Dec 10 '25 14:12

Macnique


1 Answers

I am assuming that "C:\Data\Data.exe.config" is a file that sits on the server? Keep in mind that Silverlight is executing on the client-side. Not only would you have to give Silverlight permission to access that directory (see this link for some details), but you'd be accessing the client's hard disk, not the server's. In order to get that file's contents, you'd be better off parsing the XML server-side and sending whatever settings you require from it to Silverlight via web services.

If the file really does sit on the client's computer, then you need to create an out-of-browser Silverlight project: http://msdn.microsoft.com/en-us/library/ee721082(VS.95).aspx

EDIT:

Ah, I think I see what's going on now. The Document.Load method by default assumes the URI points to a resource within the XAP: http://msdn.microsoft.com/en-us/library/bb538371(v=vs.95).aspx

What you'll probably need to do is described in this MSDN article, which will use a stream approach to loading the XML: http://msdn.microsoft.com/en-us/library/cc645034(v=vs.95).aspx#Y0

like image 97
avanek Avatar answered Dec 12 '25 03:12

avanek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!