Friday, October 29, 2010

Programtically hiding SharePoint Document Information Panel in an Office Document

Using the Document Information Panel in SharePoint to show document information in Office can be very useful for users. I've used it to show information from a custom database inside of word so that users can find out what a document is about without having to visit the SharePoint site. This is very useful for when a user gets assigned a document from a sharepoint workflow.

The problem with this was that documents that did not connect to our Document Management system would not show any data. In a perfect world, the *special* documents would use a different content type so that using a different Document Information Panel would be easy. This was not the case in our system.

SO! How do you tell Word to hide the DIP when there is no data to show?

Microsoft has put together a nice post on how to do it: http://msdn.microsoft.com/en-us/magazine/cc500578.aspx

The problem is that this does not work. This requires you to have access to the Word API. When using a SharePoint DIP you only have the InfoPath API.

When the document loads, it attempts to get data from the database. The specific key to look-up data from the database is stored as a custom column on the document. Getting this is relatively easy, and many other blogs have written about it.

When the data key is blank(a document that someone uploaded to the Doc Library, not a System generated file), we are unable to get any data. I would like to hide the DIP in this case, but we can't!

Instead, I created a blank view. Then, in the OnLoad event, when the data can't be loaded, I set the default view to be the blank view. You could also do this the other way. Set the blank view as the default and then if data loads OK, set it to be your nice, pretty, data filled view.



The code to set the default view is simple:
e.SetDefaultView("Blank") ;

Where e is passed to you in the FormEvents_Loading parameter: LoadingEventArgs e


Problem Solved!
I also put a nice note on the data filled view that says the data was unable to load, just in case someone switches over to that view.