using System;
using Windows.UI.Xaml; //EventArgs
using Windows.UI.Xaml.Controls; //Page
using Windows.Storage.Pickers;
using Windows.Storage;
using Windows.Storage.AccessCache;
using System.Threading.Tasks; //Tasks
using System.Linq; //FirstOrDefault()
using System.Collections.Generic; //IReadOnlyList
using UserControls; //UserControls
namespace Smartphone_Imagefolder_lesen
{
/// <summary>
/// An empty page that can be used
on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void BtnGetDevices_Click(object sender, RoutedEventArgs e)
{
//get camera folder
StorageFolder cameraFolder = await fxGetCameraFolder();
if (cameraFolder != null)
{
//*read photos+videos
fxReadFiles_inFolder(cameraFolder);
}
}
public async Task<StorageFolder>
fxGetCameraFolder()
{
//------------< fxGetCameraFolder()------------
StorageFolder cameraFolder = null;
// Get the logical root folder for all
external storage devices.
StorageFolder externalDevices =
Windows.Storage.KnownFolders.RemovableDevices;
// Get the first child folder, which
represents the SD card.
StorageFolder sdCard = (await
externalDevices.GetFoldersAsync()).FirstOrDefault();
if (sdCard != null)
{
//-----< Is sdCard >-----
//*get Smartphone as drive.
//*smartphone has to be connected and
unlocked
IReadOnlyList<StorageFolder> folderList = await sdCard.GetFoldersAsync();
//----< @loop: Smartphone folders
>----
//*read folder and search for
/DCIM/camera
foreach (StorageFolder folder in folderList)
{
//---< check smartphone Folder
>----
String sFoldername =
folder.Name;
Console.WriteLine( "Smartphone
Folder:" +
sFoldername);
//--< 1.fast: look for /DCIM/camera
>--
Console.WriteLine("read DCIM");
StorageFolder folderDCIM
= await folder.GetFolderAsync("DCIM");
if (folderDCIM != null)
{
//-< lookup: camera folder
>-
Console.WriteLine("read camera
folder");
cameraFolder = await folderDCIM.GetFolderAsync("camera");
if (cameraFolder != null)
{
break; //*stop searchloop
}
//-</ lookup: camera folder
>-
}
//--</ 1.fast: look for /DCIM/camera
>--
//--< 2.slow: loop for /DCIM/camera
>--
foreach (StorageFolder subFolder in folderList)
{
if (subFolder.Name == "DCIM")
{
//--< @Loop: Search camera
>--
foreach (StorageFolder subSubFolder in folderList)
{
//---</ check camera folder
>----
if (folder.Name == "camera")
{
//< IsCamera folder >
cameraFolder = folder;
break;
//</ IsCamera folder >
}
//---< check camera folder
>----
};
//--</ @Loop: Search camera
>--
}
//--</ 2.slow: loop for
/DCIM/camera >--
}
//---</ check smartphone Folder
>----
}
//----</ @loop: Smartphone folders
>----
//-----</ is sdCard >-----
}
return cameraFolder;
//------------</
fxGetCameraFolder()------------
}
public async void fxReadFiles_inFolder(StorageFolder
folder)
{
//------------<
fxReadFiles_inFolder()------------
ctlFiles.Items.Clear();
//< check >
if (folder == null) return;
//</ check >
//----< @Loop: Files in Folder
>----
foreach (StorageFile file in await folder.GetFilesAsync())
{
//--< File >--
Console.WriteLine(file.DisplayName);
GridViewItem item = new GridViewItem();
item.Margin = new Thickness(1);
if (file.ContentType.Contains("video") || file.ContentType.Contains("image"))
{
//----< Ist Image >----
UcFile ucImage = new UcFile();
ucImage.file = file;
//item.Content = ucImage;
//< anfuegen >
item.Content = ucImage;
ctlFiles.Items.Add(item);
//< anfuegen >
//----</ Ist Image >----
}
//--</ File >--
}
//----</
@Loop: Files in Folder >-----
//------------</
fxReadFiles_inFolder()------------
}
}
}
|