Skip to main content
1 of 2

If you have the pageItem which is an instance of Sitecore.Data.Items.Item class, you can wrap your code into a DatabaseSwitcher and DeviceSwitcher

        using (new DatabaseSwitcher(pageItem.Database))
        {
            using (new DeviceSwitcher(pageItem.Database.Resources.Devices.GetAll().Where(t=>t.Name.Equals("default",System.StringComparison.OrdinalIgnoreCase)))))
            {
                // Add your code block here
            }
        }