![](/img/trans.png)
[英]System.UnauthorizedAccessException: Access to the path:PATH is denied
[英]FileStream to open an image “System.UnauthorizedAccessException” Access to the path is denied
我正在写一个wp8应用程序。 我有一个问题困扰我几天。 我想将照片上传到服务器。 我从相册中选择一张照片,并使用FileStream上传它,但是无法打开它。 它说访问该路径被拒绝。
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); 我遇到一个错误。
System.UnauthorizedAccessException:拒绝访问路径“ C:\\ Data \\ Users \\ Public \\ Pictures \\ Camera Roll \\ WP_20140331_001.jpg”。
我在WMAppMainfest.xml中选择了功能`D_CAP_MEDIALIB_PHOTO
我认为您无法像那样访问相机胶卷。 您可能必须使用MediaLibrary类。 另外,您还可以在PhotoChooserTask_Completed事件处理程序中找到图像。 您不必进入文件流。
我看到你自己解决了你的问题,在这里仍然没有解决代码,我希望有人会用到它:)
var imageAsByteArray = File.ReadAllBytes(imagePath);
// I use as example a pictureBox:
pictureBox1.Image = byteArrayToImage(imageAsByteArray);
// Or safe/copy/replace it:
File.WriteAllBytes(picture_Path, imageAsByteArray);
您也可以立即删除(新)图片! (如果你想)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.