tags:

views:

51

answers:

2

I am new to Silverlight and I am trying to do a directory listing of the contents of a directory. However when the first list of this code runs, it throws an exception:

The application itself runs inside of a Browser.

File operation not permitted. Access to path 'C:\Program Files\AppName' is denied.

I checked permissions and they are readable so I'm not sure why it's not working.

    DirectoryInfo di = new DirectoryInfo(@"C:\Program Files\AppName");

    try
    {
        if (di.Exists)
        {
            Console.WriteLine("That path exists already.");
        }
    }
    catch (Exception e)
    {
        Console.WriteLine("The process failed: {0}", e.ToString());
    }
    finally { }
+1  A: 

Silverlight doesn't let you just access any old directory you want. Silverlight 4 added the ability to access certain well-known paths under the user profile but only in out-of-browser elevated trust applications.

Silverlight is probably not the technology you want to use for this purpose. Look into WPF instead.

Josh Einstein
The application itself is Silverlight and I dont think I can just throw in some WPF calls since it's sandboxed as you said in Silverlight. Is there any other way to get it to work?
Brock Woolf
If there was then silverlight would be one mighty bad ria platform (what you want to do has large security implications)
Matt Greer
Brock Woolf
A: 

If you want to save/load files in silverlight and your app owns the files, you can use isolated storage.

silverlight isolated storage example

Generally, this is useful to store cross-session data locally, or store user settings. Like Josh's answer says, there is no solution to your problem if you need to access other app's files.

StephaneT