开发者

Can I use a StreamReader to read from a file in Silverlight?

I'm trying to read in some sample data from an XML file in a Silverlight project, and this line:

using (TextReader reader = new StreamReader(@"C:\Users\mike\Documents\Visual Studio 2008\Projects\test\test\Data\test.xml"))

Throws this exception:

System.MethodAccessException: Attempt to access the method failed: System.IO.StreamReader..ctor(System.String)

--- Inner Exception --- Attempt to access the method failed: System.IO.StreamReader..ctor(System.String)

I'm positive that 开发者_运维技巧the path is correct, I copied it out of explorer (pasting the filename at the end) to be sure.

What might cause this problem?


Silverlight runs in a different security context enforced by browsers. You cannot access the file system at your will. Image if you can, some one can write a silverlight program that deletes users files once the web page is opened.


You'll want to look into OpenFileDialog if you want to open a file in Silverlight.


You can only StreamRead a file from SilverLight if it's on the server.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜