I can't show the real name of my photos of my picture library in windows phone 8. I have a there photos whose original names are: chucktodd-einstein-2010-1.jpg, chucktodd-einstein-2010-2.jpg,chucktodd-einstein-2010-3.jpg.
I execute this code:
MediaLibrary m = new MediaLibrary();
for (int j = 0; j < m.Pictures.Count; j++)
{
var r = m.Pictures[j];
MessageBox.Show(r.Name);
}
And MessageBox show always this name : "Einstein writing on a blackboard with chalk illustration by chuck Todd 2010".
How can you Obtain the original name?
As the official documentation shows, when accessing the
MediaLibrary
and looping through the resultingPicture
list, there is no relative path, absolute path or filename for each image.But there is access to date, name (description, if any) and a few other properties - so the solution is to generate your own filename when needed.
If we look at how the built-in Windows Phone Camera app and auto-upload to Skydrive feature works, my Skydrive camera roll has the following filenames:
The pattern above is very easy to see an reproduce (and replace WP with the name of your app):
You may be tempted to use the
name
property (ie. description) to generate a desktop-like filename butname
appears to be optional so it's blank most of the time, in my experience.I found this Library and fixed this issue:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.phoneextensions.medialibraryextensions.getpath(v=xnagamestudio.42).aspx
With this code I obtain the full path of file with the original name.
You can try this:
and then strip the folder in the path.
The MediaLibrary API does not provide access to the original file name.
Picture.Name
seems to have the name given by the application that saved the picture. For example, for images downloaded from web by IE, it contains something likeC:\Data\Users\DefApps\AppData\INTERNETEXPLORER\Temp\Saved Images\image.jpg
. If image is saved by SkyDrive app, the name does not contain the.jpg
extension at all.