How do I add tags / keywords to a windows file properties details tab using C#

安稳与你 提交于 2019-12-10 18:19:54

问题


Ideally I would like to use the shell class to add tags to my office documents but I think the tags property is a read only item this way. Does anyone have any other ways?

There is very little on the subject. Thank you for your help.


回答1:


I looked into the shellfile class a little more. The answer was staring me right in the face.

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

to get the keywords already added to the file use:

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

if (tags.Length != 0)
{
    foreach (string str in tags)
    {
        // code here
    }
}

and done!



来源:https://stackoverflow.com/questions/34736458/how-do-i-add-tags-keywords-to-a-windows-file-properties-details-tab-using-c-sh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!