2014-03-31 57 views
0

我在写一个wp8应用程序。我有一个问题困扰了我几天。 我想将照片上传到服务器。我从相册中选择一张照片,然后使用FileStream上传它,但我无法打开它。它说,访问路径被拒绝。FileStream打开图像“System.UnauthorizedAccessException”访问路径被拒绝

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 =新的FileStream(的ImagePath,FileMode.Open,FileAccess.Read); 我遇到了一个错误。

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

我选择了功能`D_CAP_MEDIALIB_PHOTO在WMAppMainfest.xml

回答

1

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

+1

我成功解决了这个问题。我从e.ChosenPhoto获取流并传输到字节[]上传。谢谢! – user3482142

相关问题