不允许文件操作。访问路径'C:\ Desert.jpg'被拒绝。 [英] File operation not permitted. Access to path 'C:\Desert.jpg' is denied.

查看:132
本文介绍了不允许文件操作。访问路径'C:\ Desert.jpg'被拒绝。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我正在使用WCF服务创建一个silverlight应用程序。在我的应用程序中,我正在尝试从本地路径读取图像,而使用以下代码读取图像文件时会出现以下异常。

I am creating a silverlight application,in this am using a WCF service too. In my application i am trying to read a image from my local path, while reading an image file by using the following code am getting the following exception.

读取图像文件的代码:



BitmapImage bitmapImage = new BitmapImage();
            var file = File.OpenRead(@"C:\Desert.jpg");
            bitmapImage.SetSource(file);
            byte[] imageData = new byte[file.Length];
            file.Read(imageData, 0, imageData.Length);


Exception am getting is as follows:



System.Security.SecurityException was unhandled by user code
  Message=File operation not permitted. Access to path 'C:\Desert.jpg' is denied.
  StackTrace:
       at System.IO.FileSecurityState.EnsureState()
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.File.OpenRead(String path)
       at SilverlightApplication2.MainPage.Button_Click(Object sender, RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  InnerException:


Please help me anybody.




-Ramesh


-Ramesh

推荐答案

除了隔离存储外,silverlight无法访问任何内容。

silverlight can not access anything but the isolated storage.

图片应该在xap文件中嵌入。

images should be embed within the xap file.

 

您还可以考虑向用户展示一个OpenFileDialog,允许用户从他想要的任何地方选择文件

you can also consider to show the user an OpenFileDialog which allow the user the select file from any where he wants


这篇关于不允许文件操作。访问路径'C:\ Desert.jpg'被拒绝。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆