Skip to content

Instantly share code, notes, and snippets.

View hermanussen's full-sized avatar

Robin Hermanussen hermanussen

View GitHub Profile
/// <summary>
/// Imports an image into the root of the Sitecore media library
/// </summary>
/// <param name="sampleImage"></param>
public static void ImportImage(string sampleImage)
{
FileInfo imageFile = new FileInfo(sampleImage);
Item parentItem = Sitecore.Context.Database.GetItem("/sitecore/media library");
var mediaCreatorOptions = new MediaCreatorOptions();
USE [SitecoreWebsiteSitecore_Master]
-- Search for all items named 'Sample' and output their paths and template names
SELECT [ID]
, [dbo].SC_GetPath([ID]) as [Path]
, [dbo].SC_GetName([TemplateID]) as [Template Name]
FROM [Items] a
where Name = 'Sample'
USE [SitecoreWebsiteSitecore_Master]
GO
/****** Object: UserDefinedFunction [dbo].[SC_GetName] Script Date: 06/21/2012 21:59:44 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SC_GetName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[SC_GetName]
GO
/****** Object: UserDefinedFunction [dbo].[SC_GetPath] Script Date: 06/21/2012 21:59:44 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SC_GetPath]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[SC_GetPath]
GO
[TestMethod]
[Description("Tests the import of a KML file")]
public void TestKmlImport()
{
string sampleKmlFile = ConfigurationManager.AppSettings["samplekml"];
DateTime timeStamp = DateTime.Today;
SampleSitecoreLogic.ImportKml(sampleKmlFile, timeStamp);
// Check if the import root node is available
Item imported = Sitecore.Context.Database.GetItem(string.Format("/sitecore/content/Imported content {0}", timeStamp.ToString("yyyy MM dd")));
/// <summary>
/// Takes KML XML input and creates some Sitecore items with the 'Placemark' template.
/// </summary>
/// <param name="kmlDocument"></param>
/// <param name="timeStamp">Current date, to be used for the Sitecore folder name under which imported items are placed</param>
public static void ImportKml(XDocument kmlDocument, DateTime timeStamp)
{
Item folderTemplate = Sitecore.Context.Database.GetItem(Sitecore.TemplateIDs.Folder);
Item placemarkTemplate = Sitecore.Context.Database.GetItem("/sitecore/templates/User Defined/Kml/Placemark");
Item contentRoot = Sitecore.Context.Database.GetItem(Sitecore.ItemIDs.ContentRoot);
javascript:(function(){var wallPaper=document.getElementById('Wallpaper');if(wallPaper!=null){wallPaper.src='http://christmasstockimages.com/free/decorations/red_baubles.jpg';wallPaper.setAttribute('style','display:block;');}var desktop=document.getElementById('Desktop');if(desktop!=null){desktop.setAttribute('style','');}setInterval(function(){var iframes=document.getElementsByTagName('iframe');for(var i=0;i<iframes.length;i++){var iframedoc=iframes[i].contentDocument;if(iframedoc.getElementById('christmasstyle')==null){var cssNode=iframedoc.createElement('link');cssNode.id='christmasstyle';cssNode.type='text/css';cssNode.rel='stylesheet';cssNode.href='http://hermanussen.eu/sitecore/bookmarklets/christmas.css?rnd='+Math.random();cssNode.media='screen';cssNode.title='dynamicLoadedSheet';iframedoc.getElementsByTagName("head")[0].appendChild(cssNode);}}},1000);var cssNode=document.createElement('link');cssNode.id='christmasstyle';cssNode.type='text/css';cssNode.rel='stylesheet';cssNode.href='http://hermanussen.
<%@ Page Language="C#" AutoEventWireup="true" Debug="true" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.Diagnostics" %>
<%@ Import Namespace="Sitecore.Data.SqlServer" %>
<script runat="server">
private SqlServerDataApi dataApi = new SqlServerDataApi(
Sitecore.Configuration.Settings.GetConnectionString(Sitecore.Context.Database.ConnectionStringName)
);
/// <summary>
/// A complex example that returns the actual descendants that inherit from a specific template id.
/// </summary>
/// <param name="item">The item for which to determine the descendants.</param>
/// <param name="templateId">The ID of the template of which the result items have to inherit.</param>
/// <returns>The actual descendants that inherit from the template that was passed.</returns>
public IEnumerable<Item> GetDescendantsInheritingTemplate(Item item, Sitecore.Data.TemplateID templateId)
{
Assert.IsNotNull(item, "A valid Sitecore item must be provided to this method");
item.Axes.GetDescendants()
.Where(desc => InheritsFromTemplate(desc.Template, FileTemplateId))
private bool InheritsFromTemplate(TemplateItem templateItem, Sitecore.Data.ID templateId)
{
return templateItem.ID == templateId
|| (templateItem.BaseTemplates != null
&& templateItem.BaseTemplates
.Where(baseTempl => InheritsFromTemplate(baseTempl, templateId)).Count() > 0);
}