Locate.ContentLoader() when using Episerver search

Mats Knutsen-Valen
Member since: 2010
 

Hi,

im looking at the Search example at the SDK developer guide : http://sdkbeta.episerver.com/SDK-html-Container/?path=/SdkDocuments/CMS/7/Knowledge%20Base/Developer%20Guide/Search/FullTextSearchCMSIntegration.htm&vppRoot=/SdkDocuments//CMS/7/Knowledge%20Base/Developer%20Guide/

When I am doing a copy/paste of the sample code for searching pages I get error on all the lines with Locate.<something> . I googled and found some code using : 

var context = new InitializationEngine();

context.Locate.ContentLoader() 

this does however give me an object reference is null error.

What am I doing wrong ? 

#64302 Dec 17, 2012 14:14
  • Mats Knutsen-Valen
    Member since: 2010
     

    The code I found is from this link: 

    http://sdkbeta.episerver.com/SDK-html-Container/?path=/SdkDocuments/CMS/7/Knowledge%20Base/Developer%20Guide/Partial%20Routing/News%20partial%20routing%20example.htm&vppRoot=/SdkDocuments//CMS/7/Knowledge%20Base/Developer%20Guide/#Controller

     

    public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
        {
            var startPage = context.Locate.ContentLoader().Get<PageData>(PageReference.StartPage);
    
            //There should be a property on start page that sets the newsContainer page.
            var partialRouter = new NewsPartialRouter(new NewsContentStore(), startPage["NewsContainer"] as ContentReference);
            RouteTable.Routes.RegisterPartialRouter<NewsContainer, NewsContent>(partialRouter);
    
            NewsContentGenerator.CreateFakeData();
        }
    
     
    #64312 Dec 17, 2012 15:40
  • Mats Knutsen-Valen
    Member since: 2010
     

    Solved it by fetching the ServiceLocationHelper :

     var serviceLocationHelper = ServiceLocator.Current.GetInstance<ServiceLocationHelper>();

     serviceLocationHelper.ContentLoader()

    #64325 Dec 18, 2012 9:22