After adding metadata property handler for.svg extension with this tool , I am able to add keywords to.svg files via Windows Explorer.
I am now searching a way to add keywords via a C# application. I found this solution but System.AccessViolationException
is thrown with the code:
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;
What can be the cause?
Edit:
This method works correctly but COMException
is thrown if tag length is too high.
using DSOFile;
var file = new OleDocumentProperties();
file.Open(path);
file.SummaryProperties.Keywords = string.Join(";", tags);
file.Close(true);
This works for me:
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.