"Who would'a thunk it?"
It turns out that saving a list template (or document library template) involves document parsing. In hindsight this appears obvious, but it's not documented anywhere, and in any case the wisdom of making list template creation dependent on a flag that can be switched off for unrelated reasons, is very questionable.
The fix, although not 100% perfect, involves building an ItemAdded event receiver for list items. The magic lines of code look like this:
public override void ItemAdded(SPItemEventProperties properties)
{
if (properties.Web.ParserEnabled == false)
{
if (properties.ListTitle.Equals("List Template Gallery"))
{
string propKey = "CheckInComment";
string propValue = "Triggered Programmatically by Event Receiver";
try
{
if (properties.ListItem.File != null)
{
properties.Web.ParserEnabled = true;
properties.Web.Update();
// Once document parsing is enabled, all we need to do to trigger it
// is change one (insignificant) property of the Properties of the
// SPFile object containing the template itself.
if (properties.ListItem.Properties.ContainsKey(propKey))
properties.ListItem.Properties[propKey] = propValue;
else
properties.ListItem.File.Properties.Add(propKey, propValue);
properties.ListItem.File.Update();
// Set the flag back to the way it was; we're done.
properties.Web.ParserEnabled = false;
properties.Web.Update();
}
}
catch (Exception ex)
{
Trace.WriteLine(String.Format("--- Exception while forcing property promotion: {0}\r\n {1}\r\n", ex.Message, ex.StackTrace));
}
}
}
}
There is a small problem with this solution: document parsing is enabled for the several seconds it takes to save the template, and during that time "unforeseen events" may take place. The obvious first attempt to solve this attempts to set the site collection's WriteLocked flag; however, that stops not only unsuspecting users - it also stops this code from doing its work.
If anyone out here knows how to prevent "everyone but me" from writing to SharePoint, please let me know.
TIA
Josh