首页 > 解决方案 > 添加自定义文件扩展属性

问题描述

使用此工具为 .svg 扩展添加元数据属性处理程序后,我可以通过 Windows 资源管理器将关键字添加到 .svg 文件。

FileMeta 关联管理器

我现在正在寻找一种通过 C# 应用程序添加关键字的方法。我找到了这个解决方案,但System.AccessViolationException被代码抛出:

using Microsoft.WindowsAPICodePack.Shell;

var tags = new[] {"foo", "bar"};
var file = ShellFile.FromFilePath(path);
// following statement throws System.AccessViolationException
file.Properties.System.Keywords.Value = tags;

可能是什么原因?


编辑:

此方法可以正常工作,但COMException如果标签长度太长则会被抛出。

using DSOFile;

var file = new OleDocumentProperties();
file.Open(path);
file.SummaryProperties.Keywords = string.Join(";", tags);
file.Close(true);

标签: c#.netwindows-api-code-packfile-propertiespropertyhandler

解决方案


推荐阅读