Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

For some very unusual reason (if I knew what it was, I wouldn't be asking the question here 8-)), when I save a given list as a template, SP2010 creates the template and claims it was successful.

However, when I go to create a new list based on the template I created, the template doesn't show up as one of the available choices.

One clue as to what might be going wrong is when I see the template in the list template gallery: where all other templates have Language=English, this one has Language=1033 (which happens to be the locale-id for English); where all other templates have ProductVersion=4, this one has ProductVersion=null, and where other templates have a Feature ID, this one has a null feature ID.

Does anyone here have any idea what might be causing this?

TIA Josh

p.s. The result is the same regardless of whether the Publishing infrastructure is activated or deactivated; the site collection UI is version 3 (i.e. SP2007).

share|improve this question
add comment

1 Answer 1

"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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.