Storing metadata attached to uploaded files

Each UnidfiedFile object has a Summary property that you can use to access meta data about the file that is stored in the database (i.e. Author, Category, Comments, Keywords, Subject and Title).

These properties can be edited through the file manager if you provide a valid FileSummary.config in the customFileSummary attribute of the virtualPath element. This XML document is used to create an XForm class that shows the meta data in the File Manager.

You can also edit the meta data from you own code. Remember to call SaveChanges() to make the change persistent. (Calling SaveChanges will also queue the file for re-indexing so your changes to keywords, etc will be searchable.)

There is also a Dictionary property that allows you to add your own meta data.

UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(yourVirtualPathToTheFileHere) as UnifiedFile;
file.Summary.Comments = "Changed from code";
file.Summary.Dictionary["ImageWidth"] = 1234;

It is possible to add your own keys with the Dictionary property and a key does not have to be in the fileSummary.config as far as I can understand making it possible to add meta data that is invisible to the editor.

All values are stored in a hash table so access is quite fast but the file object itself is serialized to and from the database so I would keep an eye open for performance issues because I do not know how well the caching works and of course, updates would always trigger database activity.

Also worth to mention is that uploaded files are versioned and each version can have a different set of meta data.

(Read more about uploaded files in EPiServer in previous blog post)