Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

c# - Custom File Properties

I need to following:

In my application I have documents. Documents which need to be checked in and out all the time. When I check a Document out of my application I need to add Custom Properties to the file so I can identify it later when I'm going to checkin the document.

I've tried to use the OleDocumentProperties from DSOFile using the following code, but no success:

 // Adding custom properties to file (Parameters: FileName, custom property name, value, debug: true/false
 DocumentProperties.WriteDocumentProperty(filename, "dms_dossiernummer", _dossiernummer.ToString(), false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_zaaknaam", ReturnZaaknaam(_dossiernummer), false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_verantw_medew", ReturnVerantwMedew(_dossiernummer), false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_document_path", path, false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_bestandsnaam", bestandsNaam, false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_bestands_id", bestandId, false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_is_checkedout", "true", false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_dossier_map_id", dossierMapId, false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_bestand_versie_nummer", Queries.Dms.Selects.GetDocumentVersion(
                                                        Convert.ToInt32(bestandId)).ToString(), false);
 DocumentProperties.WriteDocumentProperty(filename, "dms_bestands_locatie", path, false);

Does anyone know another way to add Custom File Properties to a file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What is a File?

Basically, a file is just a stream of bytes and some metadata that file file system associates with it. In early file systems the metadata was basically just the file name and some date stamps. Newer file systems like NTFS have the option of adding extra metadata.

Where do Document Properties Come From?

In Windows Explorer you can see quite a lot of document properties for many file types. The nice, unified interface suggests that there is some unified property store. That's not really the case. The Explorer Shell has an extensible interface for Property Sheet Handlers that extract this information from various file types. There is a handler for JFIF (JPEG) files, and there are handlers for OLE files (old Office formats), and the new Office formats too.

Where Should I Put My Metadata?

The conclusion is:

  • If you can guarantee that you only need to handle certain file formats, investigate adding the metadata within the files. For example,

    • OLE properties if all your files are old-style Office documents (.doc)

    • Using the Open XML API if all your documents are new-style Office documents (.docx)

  • If you can guarantee that all installations will be on a specific file system, investigate features of the file system. Other responses have considered how you could do this with NTFS.

  • Otherwise you must devise your own data store. Companion files are an obvious possibility; you could store the metadata in a database; or you could create one file per directory to hold all the metadata for files in that directory. Consider whether you might face concurrency problems with multiple requests for the same file. Using a database might make dealing with that more straightforward.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...