0

I am trying to figure out if there is a way to read xml file (like c:\test.xml) in silverlight application? All I want is to read xml file into xmldocument. any help? I have a text box from where I read xml file path. Now I want to read that xml into xmldocument

pappu
  • 431
  • 1
  • 6
  • 7
  • this related question might help: http://stackoverflow.com/questions/1148182/does-silverlight-3-have-access-to-local-file-system-open-excel-and-print-report – Russ Clarke May 11 '11 at 01:55

1 Answers1

2

As the link that Russ provided mentions, you can't directly access a file on the hard drive with Silverlight. Typically you need to use the OpenFileDialog to retrieve the file stream. However if your Silverlight application is an Out-Of-Browser application with Elevated Permissions then you do have access to the user's Documents folder.

Also, XmlDocument is not available in Silverlight. You'll want to use the XDocument class, which is the newer way to work with XML in the latest versions of .NET.

Here's an example of using XDocument, in relation to XmlDocument: http://blogs.msdn.com/b/xmlteam/archive/2009/03/31/converting-from-xmldocument-to-xdocument.aspx

MSDN Docs on XDocument: http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument(v=VS.95).aspx

Joe McBride
  • 3,789
  • 2
  • 34
  • 38
  • 1
    You can get XDocument in Silverlight by adding a reference to System.Xml.Linq. It comes with the SL 4 install and in you C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client (on Win 7) – AlignedDev May 11 '11 at 16:26