0
votes

I'm Working on windows phone application.in my application i have a photo upload option, for this i'm using PhotoChooserTask. here is my code,

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


                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);

                string PhotoPath = e.OriginalFileName.;

                MessageBox.Show("" + PhotoPath); // just for testing

                myImage.Source = bmp;
                myImage1.Source = bmp;

            }
        }

i want to get file name of the image selected from user.

MessageBox.Show("" + PhotoPath)

which display file path,something like

c:\Data\Users\Public\Pictures\Sample Pictures\Sample_image_00.jpg

how can i get the name of image without file path?

Thanks in advance!

2

2 Answers

1
votes

Here is a helper function which will extract the filename from the path:

public static string GetFileName(string path)
{
    return new Regex(@".+\\(\S+\.\S+)", RegexOptions.IgnoreCase).Match(path).Groups[1].Value;
}
0
votes

Not sure of any in-built method, but String.Split(string) can certainly be used. The last element in the array returned by this method should be the raw file name you are expecting.