Today Someone asked me if it was possible to promote metadata from within a Visio diagram when the diagram is uploaded to a SharePoint 2010 Document Library.
Certainly. There are a number of methods to promote metadata to columns within a document library however for this example I will focus on metadata that is stored within the new Visio Web Drawing file format which cannot be extracted by SharePoint natively.
The new Visio Web Drawing file format (VDW) is a “package” however it does not conform to the OpenXML package. Because of this some special handling is needed to extract data from the VDW files as they are added to the document library.
I attached a VS2010 project that implements an Event Receiver for Document Libraries. The Event Receiver project is fairly straight forward as I simple handle the ItemAdding and ItemAdded events.
The ItemAdding handler demonstrates how to restrict uploaded files to only the VDW file format. This is a very simple implementation that only tests the file extension on the uploaded file so it could be easily fooled, but simple enough for this example.
The ItemAdded handler demonstrates how to update the List Item with the desired metadata from the VDW file that is being uploaded.
The deployed solution produces a view of a document library as shown here…
As you can see I have edited a Document Library to include a new column named Pages. The code in the ItemAdded handler simply updates this column for the List Item. The real magic is in the code that extracts the actual page names from the VDW file…for this you will need to download the attached source.