如何使用 C# 将标签/关键字添加到 Windows 文件属性详细信息选项卡

Lee*_*Lee 4 tags document file

理想情况下,我想使用 shell 类向我的办公文档添加标签,但我认为 tags 属性是这样的只读项。有没有人有其他方法?

关于这个主题的内容很少。感谢您的帮助。

Lee*_*Lee 5

我对 shellfile 类进行了更多研究。答案正直盯着我的脸。

string[] keywords = new string[x];
var shellFile = ShellFile.FromFilePath(file);
shellFile.Properties.System.Keywords.Value = keywords;
Run Code Online (Sandbox Code Playgroud)

要获取已添加到文件中的关键字,请使用:

var tags = (string[])shellFile.Properties.System.Keywords.ValueAsObject;
tags = tags ?? new string[0];

if (tags.Length != 0)
{
    foreach (string str in tags)
    {
        // code here
    }
}
Run Code Online (Sandbox Code Playgroud)

并做了!