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?
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
using Microsoft.Xna.Framework.Media.PhoneExtensions;
MediaLibrary m = new MediaLibrary();
for (int j = 0; j < m.Pictures.Count; j++)
{
var r = m.Pictures[j];
MessageBox.Show(MediaLibraryExtensions.GetPath(r));
}
With this code I obtain the full path of file with the original name.
You can try this:
r.getPath();
and then strip the folder in the path.
As the official documentation shows, when accessing the MediaLibrary
and looping through the resulting Picture
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:
- WP_20130716_001.jpg
- WP_20130716_002.jpg
- WP_20130716_003.jpg
The pattern above is very easy to see an reproduce (and replace WP with the name of your app):
- WP (underscore) ISO date format (underscore) image number
You may be tempted to use the name
property (ie. description) to generate a desktop-like filename but name
appears to be optional so it's blank most of the time, in my experience.
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 like C:\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.