Search code examples
windows-phone-8.1windows-dev-center

How to get a storage file from camera roll in windows phone 8.1


How can I create a Windows.Storage.StorageFile from a picture in Camera Roll for windows phone 8.1? I have tried the follwing:-

try{
    Windows.Storage.StorageFolder folder = Windows.Storage.KnownFolders.CameraRoll;
    Windows.Storage.StorageFile file = await folder.GetFileAsync(filename);
   }
   catch(Exception exc) 
   {
      MessageBox.Show(exc.Message);
   }

Which is producing an Access Violation Exception. Can someone plz tell me how to do it in windows phone 8.1?


Solution

  • First, you may need to declare the capability in the package.appxmanifest. enter image description here

    Once you’ve done this you can now use the Windows.Storage.KnownFolders class to access the Picture Library.

    Here is how to get to the camera roll, you can refer to.

    public async Task<IEnumerable<StorageFile>> GetFilesInCameraRoll()
    

    { var cameraRoll = await KnownFolders.PicturesLibrary.GetFolderAsync("Camera Roll");

    return await cameraRoll.GetFilesAsync();
    

    }

    More detailed information, you can refer to Access Camera Roll in Windows Phone 8.1