Determining whether an EPiServer page is created by import or not

by Fredrik Karlsson 19. November 2009 13:30

This is one of the hidden gems in EPiServer CMS. It basicly allows you to determine if the page is being created by an import (export/import, mirroring) or not (manually, by code). It is done by checking the CurrentITransferContext in your event. We had this problem in Composer and really had some dirty workarounds for it until we had the oppertunity to talk to MagnusS about it and he showed us the way.

Code

public class Global : EPiServer.Global
	{
		protected void Application_Start(Object sender, EventArgs e)
		{
            XFormControl.ControlSetup += new EventHandler(XForm_ControlSetup);
			EPiServer.DataFactory.Instance.SavingPage += new PageEventHandler(Instance_SavingPage);
        }

		void Instance_SavingPage(object sender, PageEventArgs e)
		{
			if (e.Page == null) return;
			// If it is null, then this is not an import. If it is an object, it is IMPORTING
			if (EPiServer.BaseLibrary.Context.Current["CurrentITransferContext"] != null)
			{
				// We are creating the page by import
				e.Page.PageName += " [created by import]";

			}
		}

Outcome

If you import a page now, it will have " [created by import]" after the pagename.

Tags: ,

Development

blog comments powered by Disqus

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 Sweden License.


Welcome to the Dropit blog!

Here we, the people that work at Dropit, will write about stuff that interests us. For example web development, especially with .NET and EPiServer - but we'll also talk about other techniques that interest us, marketing on the web, social phenomenons, pop culture, games and software development in general.