[英]Add custom file extended properties
使用此工具為 .svg 擴展添加元數據屬性處理程序后,我可以通過 Windows 資源管理器將關鍵字添加到 .svg 文件。
我現在正在尋找一種通過 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);
這對我有用:
using Microsoft.WindowsAPICodePack.Shell;
var shellFile = ShellFile.FromParsingName(filePath);
// This one throws an exception
// shellFile.Properties.System.Keywords.Value = new[] { "test1", "test2" };
var writer = shellFile.Properties.GetPropertyWriter();
// This works, pass keywords as single string
writer.WriteProperty(SystemProperties.System.Keywords, "test1;test2", true);
writer.Close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.