Sharepoint Feature : Uploading a site template in "Site Template Gallery"

When we try to upload a Site Template file (.stp) to the "Site Template Gallery" through a feature, it doesn't behave the way it should.
It adds the file in gallery, but it doesn't appears in "Create New Site" page.
For this purpose, you need to add a few properties for the newly added site template

In the feature activated:

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
            SPSite site = properties.Feature.Parent as SPSite;
            SPWeb web = site.RootWeb;
           // try
                #region Fix the Site Collection Template
                SPDocumentLibrary templates = (SPDocumentLibrary)web.Lists["Site Template Gallery"];
                foreach (SPListItem item in templates.Items)
                    if (item.File.Name.Equals("Template_Name.stp"))
                        item["Title"] = "Template Title";
                        item.Properties.Add("Language", "1033");
                        item.Properties.Add("TemplateTitle", "Custom Template");
                        item.Properties.Add("vti_parserversion", "");
                        item.Properties.Add("ContentTypeId", "0x00428892DDF7841D4693B8095E5D3AEDCD");
                        item.Properties.Add("TemplateID", "1");

and volla, everything should be smooth now.
6 Feb 2009

A better method is to add the language and version in the feature, like this

'<'Module Name="SiteRequestListTemplate" Url="_catalogs/lt" RootWebOnly="TRUE" Path="Templates"'>' 

    '<'File Url="Site.stp" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE"'>' 

      '<'Property Name="LanguageDisplay" Value="English" /'>' 

      '<'Property Name="Version" Value="3" /'>'