背水一战 Windows 10 (86) - 文件系统: 获取文件夹的属性, 获取文件夹的缩略图
作者:webabcd
介绍
背水一战 Windows 10 之 文件系统
- 获取文件夹的属性
- 获取文件夹的缩略图
示例
1、演示如何获取文件夹的属性
FileSystem/FolderProperties.xaml
<Page
x:Class="Windows10.FileSystem.FolderProperties"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.FileSystem"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <ListBox Name="listBox" Width="400" Height="200" HorizontalAlignment="Left" Margin="5" SelectionChanged="listBox_SelectionChanged" /> <TextBlock Name="lblMsg" Margin="5" /> </StackPanel>
</Grid>
</Page>
FileSystem/FolderProperties.xaml.cs
/*
* 演示如何获取文件夹的属性
*
* StorageFolder - 文件夹操作类
* 直接通过调用 Name, Path, DisplayName, DisplayType, FolderRelativeId, Provider, DateCreated, Attributes 获取相关属性,详见文档
* GetBasicPropertiesAsync() - 返回一个 BasicProperties 类型的对象
* Properties - 返回一个 StorageItemContentProperties 类型的对象
*
* BasicProperties
* 可以获取的数据有 Size, DateModified, ItemDate
*
* StorageItemContentProperties
* 通过调用 RetrievePropertiesAsync() 方法来获取指定的属性,详见下面的示例
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace Windows10.FileSystem
{
public sealed partial class FolderProperties : Page
{
public FolderProperties()
{
this.InitializeComponent();
} protected async override void OnNavigatedTo(NavigationEventArgs e)
{
// 获取“图片库”目录下的所有根文件夹
StorageFolder picturesFolder = await KnownFolders.GetFolderForUserAsync(null, KnownFolderId.PicturesLibrary);
IReadOnlyList<StorageFolder> folderList = await picturesFolder.GetFoldersAsync();
listBox.ItemsSource = folderList.Select(p => p.Name).ToList(); base.OnNavigatedTo(e);
} private async void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// 用户选中的文件夹
string folderName = (string)listBox.SelectedItem;
StorageFolder picturesFolder = await KnownFolders.GetFolderForUserAsync(null, KnownFolderId.PicturesLibrary);
StorageFolder storageFolder = await picturesFolder.GetFolderAsync(folderName); // 显示文件夹的各种属性
ShowProperties1(storageFolder);
await ShowProperties2(storageFolder);
await ShowProperties3(storageFolder);
} // 通过 StorageFolder 获取文件夹的属性
private void ShowProperties1(StorageFolder storageFolder)
{
lblMsg.Text = "Name:" + storageFolder.Name;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "Path:" + storageFolder.Path;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "DisplayName:" + storageFolder.DisplayName;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "DisplayType:" + storageFolder.DisplayType;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "FolderRelativeId:" + storageFolder.FolderRelativeId;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "Provider:" + storageFolder.Provider;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "DateCreated:" + storageFolder.DateCreated;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "Attributes:" + storageFolder.Attributes; // 返回一个 FileAttributes 类型的枚举(FlagsAttribute),可以从中获知文件夹是否是 ReadOnly 之类的信息
lblMsg.Text += Environment.NewLine;
} // 通过 StorageFolder.GetBasicPropertiesAsync() 获取文件夹的属性
private async Task ShowProperties2(StorageFolder storageFolder)
{
BasicProperties basicProperties = await storageFolder.GetBasicPropertiesAsync();
lblMsg.Text += "Size:" + basicProperties.Size;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "DateModified:" + basicProperties.DateModified;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "ItemDate:" + basicProperties.ItemDate;
lblMsg.Text += Environment.NewLine;
} // 通过 StorageFolder.Properties 的 RetrievePropertiesAsync() 方法获取文件夹的属性
private async Task ShowProperties3(StorageFolder storageFolder)
{
/*
* 获取文件夹的其它各种属性
* 详细的属性列表请参见结尾处的“附录一: 属性列表”或者参见:http://msdn.microsoft.com/en-us/library/windows/desktop/ff521735(v=vs.85).aspx
*/
List<string> propertiesName = new List<string>();
propertiesName.Add("System.DateAccessed");
propertiesName.Add("System.DateCreated");
propertiesName.Add("System.FileOwner"); StorageItemContentProperties storageItemContentProperties = storageFolder.Properties;
IDictionary<string, object> extraProperties = await storageItemContentProperties.RetrievePropertiesAsync(propertiesName); lblMsg.Text += "System.DateAccessed:" + extraProperties["System.DateAccessed"];
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "System.DateCreated:" + extraProperties["System.DateCreated"];
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "System.FileOwner:" + extraProperties["System.FileOwner"];
lblMsg.Text += Environment.NewLine;
}
}
} /*
----------------------------------------------------------------------
附录一: 属性列表 System.AcquisitionID
System.ApplicationName
System.Author
System.Capacity
System.Category
System.Comment
System.Company
System.ComputerName
System.ContainedItems
System.ContentStatus
System.ContentType
System.Copyright
System.DataObjectFormat
System.DateAccessed
System.DateAcquired
System.DateArchived
System.DateCompleted
System.DateCreated
System.DateImported
System.DateModified
System.DefaultSaveLocationIconDisplay
System.DueDate
System.EndDate
System.FileAllocationSize
System.FileAttributes
System.FileCount
System.FileDescription
System.FileExtension
System.FileFRN
System.FileName
System.FileOwner
System.FileVersion
System.FindData
System.FlagColor
System.FlagColorText
System.FlagStatus
System.FlagStatusText
System.FreeSpace
System.FullText
System.Identity
System.Identity.Blob
System.Identity.DisplayName
System.Identity.IsMeIdentity
System.Identity.PrimaryEmailAddress
System.Identity.ProviderID
System.Identity.UniqueID
System.Identity.UserName
System.IdentityProvider.Name
System.IdentityProvider.Picture
System.ImageParsingName
System.Importance
System.ImportanceText
System.IsAttachment
System.IsDefaultNonOwnerSaveLocation
System.IsDefaultSaveLocation
System.IsDeleted
System.IsEncrypted
System.IsFlagged
System.IsFlaggedComplete
System.IsIncomplete
System.IsLocationSupported
System.IsPinnedToNameSpaceTree
System.IsRead
System.IsSearchOnlyItem
System.IsSendToTarget
System.IsShared
System.ItemAuthors
System.ItemClassType
System.ItemDate
System.ItemFolderNameDisplay
System.ItemFolderPathDisplay
System.ItemFolderPathDisplayNarrow
System.ItemName
System.ItemNameDisplay
System.ItemNamePrefix
System.ItemParticipants
System.ItemPathDisplay
System.ItemPathDisplayNarrow
System.ItemType
System.ItemTypeText
System.ItemUrl
System.Keywords
System.Kind
System.KindText
System.Language
System.LayoutPattern.ContentViewModeForBrowse
System.LayoutPattern.ContentViewModeForSearch
System.LibraryLocationsCount
System.MileageInformation
System.MIMEType
System.Null
System.OfflineAvailability
System.OfflineStatus
System.OriginalFileName
System.OwnerSID
System.ParentalRating
System.ParentalRatingReason
System.ParentalRatingsOrganization
System.ParsingBindContext
System.ParsingName
System.ParsingPath
System.PerceivedType
System.PercentFull
System.Priority
System.PriorityText
System.Project
System.ProviderItemID
System.Rating
System.RatingText
System.Sensitivity
System.SensitivityText
System.SFGAOFlags
System.SharedWith
System.ShareUserRating
System.SharingStatus
System.Shell.OmitFromView
System.SimpleRating
System.Size
System.SoftwareUsed
System.SourceItem
System.StartDate
System.Status
System.StatusBarSelectedItemCount
System.StatusBarViewItemCount
System.Subject
System.Thumbnail
System.ThumbnailCacheId
System.ThumbnailStream
System.Title
System.TotalFileSize
System.Trademarks
----------------------------------------------------------------------
*/
2、演示如何获取文件的缩略图
FileSystem/FileThumbnail.xaml
<Page
x:Class="Windows10.FileSystem.FileThumbnail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.FileSystem"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <TextBlock Name="lblMsg" Margin="5" /> <ListBox Name="listBox" Width="400" Height="200" HorizontalAlignment="Left" Margin="5" SelectionChanged="listBox_SelectionChanged" /> <Image Name="imageThumbnail" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5" /> </StackPanel>
</Grid>
</Page>
FileSystem/FileThumbnail.xaml.cs
/*
* 演示如何获取文件的缩略图
*
* StorageFile - 文件操作类。与获取文件缩略图相关的接口如下
* public IAsyncOperation<StorageItemThumbnail> GetThumbnailAsync(ThumbnailMode mode);
* public IAsyncOperation<StorageItemThumbnail> GetThumbnailAsync(ThumbnailMode mode, uint requestedSize);
* public IAsyncOperation<StorageItemThumbnail> GetThumbnailAsync(ThumbnailMode mode, uint requestedSize, ThumbnailOptions options);
* ThumbnailMode mode - 用于描述缩略图的目的,以使系统确定缩略图图像的调整方式(就用 SingleItem 即可)
* uint requestedSize - 期望尺寸的最长边长的大小
* ThumbnailOptions options - 检索和调整缩略图的行为(默认值:UseCurrentScale)
*
* StorageItemThumbnail - 缩略图(实现了 IRandomAccessStream 接口,可以直接转换为 BitmapImage 对象)
* OriginalWidth - 缩略图的宽
* OriginalHeight - 缩略图的高
* Size - 缩略图的大小(单位:字节)
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation; namespace Windows10.FileSystem
{
public sealed partial class FileThumbnail : Page
{
public FileThumbnail()
{
this.InitializeComponent();
} protected async override void OnNavigatedTo(NavigationEventArgs e)
{
// 获取“图片库”目录下的所有根文件
StorageFolder picturesFolder = await KnownFolders.GetFolderForUserAsync(null, KnownFolderId.PicturesLibrary);
IReadOnlyList<StorageFile> fileList = await picturesFolder.GetFilesAsync();
listBox.ItemsSource = fileList.Select(p => p.Name).ToList(); base.OnNavigatedTo(e);
} private async void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// 用户选中的文件
string fileName = (string)listBox.SelectedItem;
StorageFolder picturesFolder = await KnownFolders.GetFolderForUserAsync(null, KnownFolderId.PicturesLibrary);
StorageFile storageFile = await picturesFolder.GetFileAsync(fileName); // 显示文件的缩略图
await ShowThumbnail(storageFile);
} private async Task ShowThumbnail(StorageFile storageFile)
{
// 如果要获取文件的缩略图,就指定为 ThumbnailMode.SingleItem 即可
ThumbnailMode thumbnailMode = ThumbnailMode.SingleItem;
uint requestedSize = ;
ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale; using (StorageItemThumbnail thumbnail = await storageFile.GetThumbnailAsync(thumbnailMode, requestedSize, thumbnailOptions))
{
if (thumbnail != null)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(thumbnail);
imageThumbnail.Source = bitmapImage; lblMsg.Text = $"thumbnail1 requestedSize:{requestedSize}, returnedSize:{thumbnail.OriginalWidth}x{thumbnail.OriginalHeight}, size:{thumbnail.Size}";
}
}
}
}
}
OK
[源码下载]
背水一战 Windows 10 (86) - 文件系统: 获取文件夹的属性, 获取文件夹的缩略图的更多相关文章
- 背水一战 Windows 10 (85) - 文件系统: 获取文件夹和文件, 分组文件夹, 排序过滤文件夹和文件, 搜索文件
[源码下载] 背水一战 Windows 10 (85) - 文件系统: 获取文件夹和文件, 分组文件夹, 排序过滤文件夹和文件, 搜索文件 作者:webabcd 介绍背水一战 Windows 10 之 ...
- 背水一战 Windows 10 (90) - 文件系统: 获取 Package 中的文件, 可移动存储中的文件操作, “库”管理
[源码下载] 背水一战 Windows 10 (90) - 文件系统: 获取 Package 中的文件, 可移动存储中的文件操作, “库”管理 作者:webabcd 介绍背水一战 Windows 10 ...
- 背水一战 Windows 10 (88) - 文件系统: 操作文件夹和文件
[源码下载] 背水一战 Windows 10 (88) - 文件系统: 操作文件夹和文件 作者:webabcd 介绍背水一战 Windows 10 之 文件系统 创建文件夹,重命名文件夹,删除文件夹, ...
- 背水一战 Windows 10 (87) - 文件系统: 获取文件的属性, 修改文件的属性, 获取文件的缩略图
[源码下载] 背水一战 Windows 10 (87) - 文件系统: 获取文件的属性, 修改文件的属性, 获取文件的缩略图 作者:webabcd 介绍背水一战 Windows 10 之 文件系统 获 ...
- 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Application Data 中的媒体
[源码下载] 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Ap ...
- 背水一战 Windows 10 (92) - 文件系统: 读写“最近访问列表”和“未来访问列表”, 管理以及使用索引
[源码下载] 背水一战 Windows 10 (92) - 文件系统: 读写“最近访问列表”和“未来访问列表”, 管理以及使用索引 作者:webabcd 介绍背水一战 Windows 10 之 文件系 ...
- 背水一战 Windows 10 (89) - 文件系统: 读写文本数据, 读写二进制数据, 读写流数据
[源码下载] 背水一战 Windows 10 (89) - 文件系统: 读写文本数据, 读写二进制数据, 读写流数据 作者:webabcd 介绍背水一战 Windows 10 之 文件系统 读写文本数 ...
- 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件
[源码下载] 背水一战 Windows 10 (11) - 资源: CustomResource, ResourceDictionary, 加载外部的 ResourceDictionary 文件 作者 ...
- 背水一战 Windows 10 (101) - 应用间通信: 通过协议打开指定的 app 并传递数据以及获取返回数据, 将本 app 沙盒内的文件共享给其他 app 使用
[源码下载] 背水一战 Windows 10 (101) - 应用间通信: 通过协议打开指定的 app 并传递数据以及获取返回数据, 将本 app 沙盒内的文件共享给其他 app 使用 作者:weba ...
随机推荐
- 配置yum源
本文转载:https://www.cnblogs.com/yangp/p/8506264.html (一)yum源概述 yum需要一个yum库,也就是yum源.默认情况下,CentOS就有一个yum源 ...
- HTML5-网页添加视频-菜鸟笔记
一.标签 <video> 在html5中,有这么个标签 <video> 标签. <video> 允许你简单的嵌入一段视频. 二.浏览器的兼容性问题 WebM 容器通 ...
- IDEA使用SpringBoot 、maven创建微服务的简单过程
使用IDEA新建一个简单的微服务 1. 打开IDEA,File -> New -> project 打开如下图1-1所示的对话框 图 1-1 2.点击"Next"按钮 ...
- Linux常用基础操作命令大全(超实用精心整理)
相信大家都对黑客那种只用命令行对电脑操作的风格惊呆了,其实你也可以做到.linux是一款不同于windows的操作系统,而且它是黑客.渗透人员.运维人员等等必会的.如果你想学习,小编下面整理的命令将会 ...
- php 二维数组按照某个键排序
$date = array_column($arr, 'run_date'); //上面得到的结果:array(0=>'2017-11-21',1=>'2017-11-20',3=> ...
- cdnbest如何查看节点和站点的流量,负载和连接信息
1. 通过查看top信息,查看该区域下所有节点和有访问量的站点的负载情况 点节点列表==>top图标 2. 查看单台节点的负载和连接信息 点节点列表==>管理 点击下图中三个红框可以查看单 ...
- extJs相关名字解释
1.initComponent 初始化部件启动 2.defaults : Object defaults属性可以包含任意个name/value属性对,这些属性将会被添加到每一个元素中...例如, ...
- DRF的解析器和渲染器
解析器 解析器的作用 解析器的作用就是服务端接收客户端传过来的数据,把数据解析成自己可以处理的数据.本质就是对请求体中的数据进行解析. 在了解解析器之前,我们要先知道Accept以及ContentTy ...
- windows、Linux同步外网NTP服务器时间
配置 Windows 时间服务以使用外部时间源 要将内部时间服务器配置为与外部时间源同步,请使用以下方法之一: 软件自动配置 Windows 时间服务 若要自动修复此问题,请单击“下载”按钮. 在“ ...
- vue入门一
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...