FileStream 打开图像“System.UnauthorizedAccessException"访问路径被拒绝 [英] FileStream to open an image "System.UnauthorizedAccessException" Access to the path is denied

查看:48
本文介绍了FileStream 打开图像“System.UnauthorizedAccessException"访问路径被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 wp8 应用程序.我有一个问题困扰了我几天.我想上传一张照片到服务器.我从相册中选择一张照片并使用 FileStream 上传它,但我无法打开它.它表示拒绝访问该路径.

I'm writing a wp8 app. I have a problem bothers me a few days. I want to uplaod an photo to server. I choose a photo from album and I use FileStream to upload it, but I cannot open it. It said that access to the path is denied.

PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);

void photoChooserTask_Completed(object sender, PhotoResult e)
{
      if (e.TaskResult == TaskResult.OK)
      {
          // show the img
          BitmapImage bmp = new BitmapImage();
          bmp.SetSource(e.ChosenPhoto);
          ShowPhoto.Source = bmp;

          // get path of img
          string imagePath = e.OriginalFileName;
      }
}

上传

if (imagePath != null)
{
     FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
     StreamContent imageContent = new StreamContent(fs);
}

在这一行:FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);我遇到了错误.

At the line: FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read); I encountered an error.

System.UnauthorizedAccessException:拒绝访问路径C:\Data\Users\Public\Pictures\Camera Roll\WP_20140331_001.jpg".

System.UnauthorizedAccessException: Access to the path 'C:\Data\Users\Public\Pictures\Camera Roll\WP_20140331_001.jpg' is denied.

我在 WMAppMainfest.xml 中选择了函数 `D_CAP_MEDIALIB_PHOTO

I have chosen the function `D_CAP_MEDIALIB_PHOTO in WMAppMainfest.xml

推荐答案

我不认为你可以这样访问相机胶卷.您可能必须为此使用 MediaLibrary 类.此外,您在 PhotoChooserTask_Completed 事件处理程序中有图像.您不必进入文件流.

I dont think you can access the Camera Roll like that. You may have to user MediaLibrary class for the same. Also, you have the image in the PhotoChooserTask_Completed event handler. You don't have to get in a File Stream.

这篇关于FileStream 打开图像“System.UnauthorizedAccessException"访问路径被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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