Reputation: 61
I have some issues to get images from media library and I would like to know if there is any option to get or automatically filter only certain images in the library. For instance let’s say that I have images like 1.jpg , 2.jpg, 3.jpg........etc. I am getting images from media library and saving all images in isolated storage, so I want to get only certain images not all images from media library , here is my code
using (MediaLibrary mediaLibrary = new MediaLibrary())
{
PictureCollection AllScreenShot = mediaLibrary.Pictures;
foreach (Picture picture in AllScreenShot)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!storage.DirectoryExists("SavedImg"))
storage.CreateDirectory("SavedImg");
if (storage.FileExists("SavedImg" + "\\" + picture.Name))
storage.DeleteFile("SavedImg" + "\\" + picture.Name);
using (IsolatedStorageFileStream file = storage.CreateFile("SavedImg" + "\\" + picture.Name))
picture.GetImage().CopyTo(file);
}
}
}
Upvotes: 1
Views: 364
Reputation: 352
This will help
var picture = media.Pictures.FirstOrLast(p => p.Name.Contains("1.jpg"));
if (picture == null)
{
// 1.jpg not found
}
else
{
//1.jpg found
}
Upvotes: 1