Click here to Skip to main content
15,916,215 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?



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

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
   'add new comment
    file.CustomProperties.Add("Comment", "Comment Inserted")
End If

Updated 26-Sep-17 9:35am
Richard MacCutchan 26-Sep-17 4:00am    
What is the question?

1 solution

The DSOFile 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[^].
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900