简体   繁体   English

在 Windows 资源管理器中显示自定义标题或列

[英]Display custom header or column in Windows Explorer

My app adds some custom metadata to files.我的应用程序向文件添加了一些自定义元数据。 I want to display it in Windows Explorer like this:我想像这样在 Windows 资源管理器中显示它:

样机 1

or this:或这个:

样机2

Is there a way to do this in .NET?有没有办法在 .NET 中做到这一点?

There are two approaches to building custom columns in Windows File Manager: using Windows Property System and Property Definitions for Cloud Storage Provider.在 Windows 文件管理器中构建自定义列有两种方法:使用 Windows 属性系统和云存储提供程序的属性定义。 You will typically use the first approach to create custom properties for file types that you own.您通常会使用第一种方法为您拥有的文件类型创建自定义属性。 You will use the second approach when displaying custom data from your document management system or any other storage.在显示来自文档管理系统或任何其他存储的自定义数据时,您将使用第二种方法。

Using a Windows Property System.使用 Windows 属性系统。

You can create custom properties for specific file types in Windows Vista and later versions.您可以在 Windows Vista 和更高版本中为特定文件类型创建自定义属性 These properties can be read-only or read-write.这些属性可以是只读的或读写的。 As well as they can be indexed by Window Search indexer and participate in the search.以及它们可以被 Window Search 索引器索引并参与搜索。 There are some limitations:有一些限制:

...property handlers cannot be implemented in managed code and should be implemented in C++. ...属性处理程序不能在托管代码中实现,而应在 C++ 中实现。

  • The property is tied to the specific file type, which typically belongs to your application.该属性与特定文件类型相关联,通常属于您的应用程序。 You can not create a property for all file types.您不能为所有文件类型创建属性。

Using Cloud Storage Provider Property Definitions使用云存储提供商属性定义

In Windows 10 Creators Update and later you can add custom columns for file systems created using Cloud Sync Engine API (Storage Provider, Cloud Filter API).在 Windows 10 Creators Update 及更高版本中,您可以为使用Cloud Sync Engine API (存储提供程序、Cloud Filter API)创建的文件系统添加自定义列。 This API is used in such tools as OneDrive.此 API 用于 OneDrive 等工具。 You will need to register a Cloud Storage Provider sync root with custom properties definitions, provide data for your custom columns and finally implement a Cloud Storage provider using Cloud File/Cloud Filter API.您需要使用自定义属性定义注册 Cloud Storage Provider 同步根,为自定义列提供数据,最后使用 Cloud File/Cloud Filter API 实现 Cloud Storage Provider。 在此处输入图片说明

Property definitions are not tied to a file type and can be added for all files.属性定义与文件类型无关,可以为所有文件添加。 Also, even though only some API is available in .NET you still can call Win32 functions and build a cloud provider using managed code only.此外,即使 .NET 中只有一些 API 可用,您仍然可以调用 Win32 函数并仅使用托管代码构建云提供程序。

Registering the Cloud Storage provider.注册云存储提供商。 Here is an example of the Storage Provider registration with custom columns in C#:以下是在 C# 中使用自定义列注册存储提供程序的示例:

StorageProviderSyncRootInfo storageInfo = new StorageProviderSyncRootInfo();
storageInfo.Path = await StorageFolder.GetFolderFromPathAsync("C:\\Users\\User1\\VFS\\");
...
        
// Adds columns to Windows File Manager. 
// Show/hide columns in the "More..." context menu on the columns header.
var proDefinitions = storageInfo.StorageProviderItemPropertyDefinitions;
proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Lock Expires", Id = 2, });
proDefinitions.Add(new StorageProviderItemPropertyDefinition { DisplayNameResource = "Lock Scope", Id = 3, });
        
StorageProviderSyncRootManager.Register(storageInfo);

A complete registration example could be found here .可以在此处找到完整的注册示例。

Providing data for property definitions.为属性定义提供数据。 To provide the data for the columns you will use StorageProviderItemProperties.SetAsync() call:要为列提供数据,您将使用 StorageProviderItemProperties.SetAsync() 调用:

IStorageItem storageItem = await Windows.Storage.StorageFile.GetFileFromPathAsync(path);
StorageProviderItemProperty propState = new StorageProviderItemProperty()
{
     Id = 3,
     Value = "Exclusive",
     IconResource = "C:\\path\\icon.ico" // The optional icon to be displayed in the Status column.
};
await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { propState });

Another approach would be implementing IStorageProviderItemPropertySource interface.另一种方法是实现IStorageProviderItemPropertySource接口。 It returns properties based on your file path.它根据您的文件路径返回属性。

Cloud Storage Provider implementation.云存储提供商实施。 Finally, you will need a complete file system implementation, supplying data for your files/folders placeholders.最后,您将需要一个完整的文件系统实现,为您的文件/文件夹占位符提供数据。 You can find complete examples in .NET/C# here :您可以在此处找到 .NET/C# 中的完整示例:

PLEASE PAY ATTENTION: THIS ANSWER IS FOR XP AND VISTA ONLY, IT IS OUTDATED请注意:此答案仅适用于 XP 和 VISTA,已过时

It can be done on XP using a Column Handler shell extension - see here: http://www.codeproject.com/Articles/3747/Explorer-column-handler-shell-extension-in-C#可以使用 Column Handler shell 扩展在 XP 上完成 - 请参见此处: http : //www.codeproject.com/Articles/3747/Explorer-column-handler-shell-extension-in-C#

However IColumnHandler is not supported on Vista and up.但是,Vista 及更高版本不支持IColumnHandler Here you have to implement PropertyHandler .在这里你必须实现PropertyHandler See Windows SDK \\Samples\\winui\\Shell\\AppShellIntegration\\PropertyHandlers .请参阅 Windows SDK \\Samples\\winui\\Shell\\AppShellIntegration\\PropertyHandlers

Each property is described by property schema XML file.每个属性都由属性架构 XML 文件描述。 This property schema must be registered with PSRegisterPropertySchema() .此属性架构必须使用PSRegisterPropertySchema()注册。 Property handler implements IInitializeWithXXX , IPropertyStore and optionally IPropertyStoreCapabilities .属性处理程序实现IInitializeWithXXXIPropertyStore和可选的IPropertyStoreCapabilities You have to register CLSID of your implementation for each file extension you want to handle.您必须为要处理的每个文件扩展名注册实现的CLSID

Unfortunately, you cannot use AllFileSystemObject or * in registration.不幸的是,您不能在注册中使用AllFileSystemObject*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM