File Not found Exception in Knownfolders.CamerRoll

474 views Asked by At

i am getting File not found exception when i try to load an image file using KnownFolders.CameraRoll property. The image is located in the CameraRoll of my windows phone 8. i have also enabled the following capabilities in my application

  <Capability Name="ID_CAP_NETWORKING" />
   <Capability Name="ID_CAP_MEDIALIB_AUDIO" />
   <Capability Name="ID_CAP_MEDIALIB_PLAYBACK" />
   <Capability Name="ID_CAP_SENSORS" />
   <Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
   <Capability Name="ID_CAP_MEDIALIB_PHOTO" />
  <Capability Name="ID_CAP_ISV_CAMERA" />

and here is my code to fetch the image.

 private async void cameraRoll_btn_Click(object sender, RoutedEventArgs
 e) {
             try {
                 StorageFile file = await Windows.Storage.KnownFolders.CameraRoll.GetFileAsync("WP_20130607_003.jpg");
                 var mem = await file.OpenAsync(FileAccessMode.Read);
                 BitmapImage bitImage = new BitmapImage();
                 bitImage.SetSource(mem.AsStream());
                 ImageView.Source = bitImage;
             }
             catch (Exception ex) {
                 MessageBox.Show(ex.Message);
             }
         }

the image WP_20130607_003.jpg is also present in camera roll and i am deploying the app to the device. it raise exception on the GetFileAsync line. can any bode give me some hint that what i am doing wrong here?

Thanks

1

There are 1 answers

0
keyboardP On BEST ANSWER

From MSDN:

Windows Phone 8: This API is not intended to be used directly from your code.

You can use the PhotoChooserTask to let the user pick a photo. Alternatively, you can use MediaLibrary.Pictures to programmatically access the pictures. For example

MediaLibrary ml = new MediaLibrary();
var picture = ml.Pictures.Where(x => x.Name.Equals("WP_20130607_003.jpg")).FirstOrDefault();
if(picture != null)  
{
   //get the image stream
   var picStream = picture.GetImage();

   //...
}