Skip to main content
updated code to fix compilation error
Source Link
Harsh Baid
  • 2.2k
  • 15
  • 42

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().WhereFirstOrDefault(t=>t.Name.Equals("default",System.StringComparison.OrdinalIgnoreCase)))))
            {
                // Add your code block here
            }
        }

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
            }
        }

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().FirstOrDefault(t=>t.Name.Equals("default",System.StringComparison.OrdinalIgnoreCase)))))
            {
                // Add your code block here
            }
        }
Source Link

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
            }
        }