I want to add some metadata properties to some files. Just like there are Owner, Computer, Title, Subject, etc for doc files, I want to be able to add some custom attributes. How can that be done?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
As already mentioned it depends on the filesystem. So this will only work with NTFS.
One way is creating ADS streams: See the edit history.
Another way is using the DSOFile-Library, which is intended to work on Office files only. But it works on every file.
First of all download the library here (x64+x86): DOWNLOAD
IMPORTANT:
Since DSO OLE is 32bit DLL it will only work, when you set your compilation target CPU to x86. Otherwise it will throw an Exception.There's also a 64bit version avaliable: How to read custom file properties in c#Then create a refernce to the COM DLL in your project (Right click on the solution -> Add reference -> COM tab -> Add "DSO OLE Document Property Reader v2.1") and use the namespace:
After that you can create your own attributes:
First of all open the file:
Create a object for yourValue:
object yourValue = "Your Value";
Then check if there's already a property like the one you want to create:
Then after checking for existing attributes, you can add the attribute:
To finish the task, save and close the file:
You can download a sample project on my homepage.
Now to the part of showing the attributes in the explorer.
You have to create a shell extension for that. For more info on that, visit the Codeproject page.
I created one, you can download it here. But you have to sign it again (look for a "how-to" on the mentioned page).
It will look like that, when right-clicking on a .css/.js/.txt-file:
Or create your own properties tab:
You can download the sample here: DOWNLOAD
For more information about Dsofile.dll and other source see Microsoft Dsofile.dll