如何将自定义属性添加到文件中 [英] How can I add a custom property to a file
本文介绍了如何将自定义属性添加到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要为文件添加自定义属性。当我用鼠标右键打开文件时,属性(例如注释)必须在详细信息选项卡中可见。
你能帮助我吗?
谢谢
Marcello
什么我试过了:
我试图使用DSOFile库添加自定义属性。
这似乎有效,但是如果我打开文件属性我没有看到添加的属性:
Hi all,
I need to add a custom property to a file. The property (ex. comment) must be visible in the detail tab when I open the file with the mouse's right key.
Can you help me?
Thanks
Marcello
What I have tried:
I have tried to add a custom property using the DSOFile library.
It's seems works, but if I open the file property I don't see the added property:
Dim file As New OleDocumentProperties
file.Open("C:\Users\mela\Desktop\file.txt", False, dsoFileOpenOptions.dsoOptionDefault)
Dim has_property As Boolean = False
For Each p As DSOFile.CustomProperty In file.CustomProperties
If p.Name = "Comment" Then
has_property = True
End If
Next
If has_property Then
For Each x As DSOFile.CustomProperty In file.CustomProperties
'update existing comment
If x.Name = "Comment" Then
x.Value = "Updated Comment"
End If
Next
Else
'add new comment
file.CustomProperties.Add("Comment", "Comment Inserted")
End If
file.Close(True)
推荐答案
DSOFile
库仅适用于Microsoft Office文件,并且仅当它们以旧的Office 2003格式保存时才适用。它不使用.txt
文件。
你需要P / Invoke结构化存储API,或使用Windows API代码包修改常规文件的自定义属性。有关详细信息,请参阅此Stack Overflow应答 [ ^ ]。
TheDSOFile
library only applies to Microsoft Office files, and only if they're saved in the old Office 2003 format. It doesn't work with.txt
files.
You'll need to P/Invoke the Structured Storage API, or use the Windows API Code Pack to modify the custom properties for regular files. For details, see this Stack Overflow answer[^].
这篇关于如何将自定义属性添加到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文