Quantcast
Channel: SharePoint 2013 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 26374

Creating a list from a list template with an event receiver

$
0
0

I know it's probably getting old, all these Web Template-related questions. Trust me, I am so over web templates at this point, the project however, is not.

So, I've successfully added a list template to the List Templates Gallery through a module, but when I attempt to create a list off of that template through my FeatureActivated event receiver I get "Error occurred in deployment step 'Activate Features': Object reference not set to an instance of an object." I understand that this is a ridiculously vague error message, what I was hoping for is maybe a better understanding of how these feature receivers are working. 

The module is working fine. The file is right where it should be, the problem lies with my receiver. 

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using (SPSite mySite = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb myWeb = mySite.OpenWeb())
                {
                    SPListTemplateCollection listTemplates = mySite.GetCustomListTemplates(myWeb);
                    SPListTemplate siteChangeTemplate = listTemplates["SiteChangeLogListTemplate"];
                    myWeb.Lists.Add("SITE Change Log", "SITE Change Log test", siteChangeTemplate);
                }
            }
        }


- Daniel


Viewing all articles
Browse latest Browse all 26374

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>