Khắc Phục
Khắc Phục

Reputation: 37

Windows phone 7: Get the name of photo stored in Libary picture?

I need to get the name of a photo which is stored in Library Picture. I have a button to create new EventHandler<PhotoResult> and an image control to display the photo. The photo must be chosen in Library Picture of WP like this:

enter image description here

I used photo chooser:

private void button1_Click(object sender, RoutedEventArgs e)
{
     PhotoChooserTask objPhotoChooser = new PhotoChooserTask();
     objPhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooseCall);
     objPhotoChooser.Show();
}

void PhotoChooseCall(object sender, PhotoResult e)
{
    switch (e.TaskResult)
    {
        case TaskResult.OK:
            BinaryReader objReader = new BinaryReader(e.ChosenPhoto);
            image1.Source = new BitmapImage(new Uri(e.OriginalFileName));
            MessageBox.Show("Photo's name: " + e.OriginalFileName.ToString());
            break;
        case TaskResult.Cancel:
            MessageBox.Show("Cancelled");
            break;
        case TaskResult.None:
            MessageBox.Show("Nothing Entered");
            break;
    }
}

But the output is path of the photo, NOT the name:

Photo's name: \Applications\Data\C80566AB-E17E-495C-81A1-3FCAE34D3DEDE\Data\PlatformData\PhotoChooser-a8208960-3597-40fc-9b4f-869afcf822b6.jpg

How can I get the name of the photo??? (I need to get PhotoChooser-a8208960-3597-40fc-9b4f-869afcf822b6.jpg)

Upvotes: 2

Views: 382

Answers (2)

sharptooth
sharptooth

Reputation: 170549

The usual way is to use System.IO.Path.GetFileName().

Upvotes: 2

user1085665
user1085665

Reputation:

Split the string with "\" as delimiter and the last entry of the resulting array contains the name of the photo. Should be easy to perform with C#.

Upvotes: 0

Related Questions