Silverlight Tip of the Day #97 – How to get an Image’s Source File Name
Once you have an image loaded how do you go back and get the original file name for the source file?
This can be accomplished through the Uri property of the images Source. However, you must first typecast the images Source to be a BitmapImage. The Uri has a property called OriginalString that returns the full relative path to the image file.
Example:
public string GetImageSourceFile(Image img)
{ BitmapImage bi = (BitmapImage) img.Source;
Uri uri = bi.UriSource;
return uri.OriginalString
}
Thank you,
--Mike Snow
Subscribe in a reader