开发者

Open File In Silverlight 4 File operation not permitted

开发者 https://www.devze.com 2023-03-06 16:25 出处:网络
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\"

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开发者_如何学C,
    Filter = "All files|*.*"
};
bool? userClickedOK = dlg.ShowDialog();

if (userClickedOK == true)
{
    textBox1.Text =  dlg.File.FullName;
}


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.


  1. 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.

  2. 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.


As far as I know you are not allowed to access user files if you don't have elevated permissions.


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.


I was having the same issue, after reading a lot about this problem that you cannot access

 dlg.File.FullName 
Instead you can use this

 dlg.File.Name 

by doing this your exception will be removed


The error also occurs if you try to access CreationTime from a FileInfo.

0

精彩评论

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