How to select a Photo from the Windows Phone Media Library using C# ?

Sometimes , the windows phone developers might be required to select the photo or image from the Windows Phone Media library in their Windows phone App .

A typically example would be uploading the profile picture of the facebook profile from a facebook App etc …

The Windows Phone 7 SDK provides the PhotoChooserTask chooser which allows the users to choose a picture from the album photo gallery or the Media library .

The Chooser “PhotoChooserTask” is defined in the namespace using Microsoft.Phone.Tasks .

To select the photo from the media library , just create an instance of the PhotoChooserTask class and call the Show Method .

The Completed event is called when a picture is selected from the the photo library and you can use one of the parameter PhotoResult to get the selected picture from your photo album.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.IO;
using System.Windows.Media.Imaging;

namespace PhoneApp4
   public partial class MainPage : PhoneApplicationPage
     // Constructor
     public MainPage()
     PhotoChooserTask selectphoto = null;
     private void button1_Click(object sender, RoutedEventArgs e)
         selectphoto = new PhotoChooserTask();
         selectphoto.Completed += new EventHandler<PhotoResult>(selectphoto_Completed);


     void selectphoto_Completed(object sender, PhotoResult e)
        if (e.TaskResult == TaskResult.OK)

            BinaryReader reader = new BinaryReader(e.ChosenPhoto);
            image1.Source = new BitmapImage(new Uri(e.OriginalFileName));


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.


  1. How to select a Photo from the Windows Phone Media Library using C# August 16, 2011 Reply
  2. romel May 28, 2012 Reply
  3. romel May 28, 2012 Reply

Leave a Reply


Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
Download - Pokemon Go for for Windows 10 (Third Party app)
Pokemon Go is one of the popular AR games for android and iOS devices and now , the game is made ava...