Reputation: 11
I have a Silverlight web application(4.0) with a select file open dialog, however I get this error when the user selects a file : "File operation not permitted Access to path '' is denied" When I try to debug it then I get this security exception "Dialogs must be user-initiated." Is there a way around this? Has anyone has tried doing this in Silverlight?
Here is my code so far which hasn't worked:
OpenFileDialog dlg = new OpenFileDialog
{
Multiselect = false,
Filter = "All files|*.*"
};
bool? userClickedOK = dlg.ShowDialog();
if (userClickedOK == true)
{
textBox1.Text = dlg.File.FullName;
}
Upvotes: 1
Views: 5006
Reputation: 4528
The error also occurs if you try to access CreationTime from a FileInfo.
Upvotes: 0
Reputation: 880
In silverlight 4, you cannot acces the FullName property, this is the cause of exception: "File operation not permitted Access to path is denied" I trien utmost but cannot find a way to get full file path of selected file without making your application OOB.
While debugging a silverlight project, if you place a break point anywhere before the dlg.ShowDialog(), in case of your code this will raise the exception: "Dialogs must be user-initiated" Simple way to avoid this exception is to place your break point after ShowDialog() line.
Upvotes: 1
Reputation: 55
I was having the same issue, after reading a lot about this problem that you cannot access
dlg.File.FullNameInstead you can use this
dlg.File.Name
by doing this your exception will be removed
Upvotes: 0
Reputation: 30097
Because of security related restrictions you cannot open file dialogs in Silverlight directly. You can only open dialogs from inside an event handler like mouse click.
Upvotes: 2
Reputation: 52321
You can't get the full name of a file. And in all cases, why would you need it? There is no reason to know where the user stores her files.
If you want to read a file, use Stream
property of the uploaded file instead.
Upvotes: 0
Reputation: 19181
As far as I know you are not allowed to access user files if you don't have elevated permissions.
Upvotes: 0