views:

622

answers:

1

Trying to open a file dialog but I get an exception when calling ShowDialog. This pice of code have always worked fine but I think when I upgrade to Silverlight 4 it caused some problem.

Code:

var dlg = new OpenFileDialog { Filter = "CSV Files (*.csv)|*.csv" }; 

if (dlg.ShowDialog() == true)

{
    Upload(dlg.File);
}

Exception:

Directory = 'dlg.File.Directory' threw an exception of type 'System.Security.SecurityException'
{System.Security.SecurityException: File operation not permitted. Access to path file.csv' is denied.
   at System.IO.FileSecurityState.EnsureState()
   at System.IO.FileInfo.get_DirectoryName()
   at System.IO.FileInfo.get_Directory()
}

It seems like it´s problem to get options for the directory because I got correct filename and file size but no information about the directory and directory name.

+1  A: 

If you are trying to debug the application then you will get this security exception. Try to run without debugging and check if you are still getting this error.

funwithcoding