Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View janhebnes's full-sized avatar

Jan Hebnes janhebnes

View GitHub Profile
@janhebnes
janhebnes / RecursiveFileSearchProgram.cs
Last active December 16, 2015 12:42
RecursiveFileSearch - compile and dump in the root of a NAS disk and run once in a while to get a full directory tree in a text file in the root allowing for quicker searches by just opening the text file - used for very large NAS shares.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecursiveFileSearch
{
class Program
@janhebnes
janhebnes / ExportNewsletterSubscribers.aspx
Created March 21, 2014 01:56
Sitecore Export Newsletter Subscribers to E-Mail list (for import in other systems)
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="Sitecore.Security.Accounts" %>
<%@ Import Namespace="Sitecore.Security.Domains" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Serialization" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
@janhebnes
janhebnes / gist:6463709
Last active December 22, 2015 11:09
Parsing Web Browser Languages can be a pain here are some code snippets we use for getting the actual browser languages
// Try to match the local date format of the browser
var userLanguages = LanguageItem.GetRequestUserLanguages();
// Ignore if no language preferences
if (userLanguages != null)
{
var culture = CultureInfo.CreateSpecificCulture(userLanguages.First().IsoCode);
return Updated.ToString("d", culture);
}
return Updated.ToString("dd.MM.yyyy");
@janhebnes
janhebnes / gist:4001318
Created November 2, 2012 13:16
Sitecore CMS - GetContentEditorWarnings AvailableLanguageVersions Quick switch between versions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore.Data.Items;
using Sitecore.Data.Managers;
using Sitecore.Globalization;
using Sitecore.Pipelines.GetContentEditorWarnings;
namespace SitecoreExtensions.Pipelines.GetContentEditorWarnings
@janhebnes
janhebnes / gist:3962756
Created October 27, 2012 02:44
Sitecore CMS - PageNotFound 404 handling using a Sitecore Item as ErrorPage
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Sitecore;
using Sitecore.Configuration;
using Sitecore.Diagnostics;
using Sitecore.Layouts;
using Sitecore.Pipelines.HttpRequest;
@janhebnes
janhebnes / gist:3946630
Created October 24, 2012 15:06
Sitecore CMS - SQL for Removing Non Image Blobs from a Sitecore Database Blob table
-- Large blob data in test/uat environments is just wastefull use of disk space
SP_SPACEUSED [Blobs]
-- FINDING ItemIds FOR RELEVANT FIELDS
-- File > Information > Extension Field
select * from Items where ID like 'C06867FE-9A43-4C7D-B739-48780492D06F'
-- File > Media > Blob Field
select * from Items where ID like '40E50ED9-BA07-4702-992E-A912738D32DC'
-- Examining the data location of the fields
@janhebnes
janhebnes / BuildTasks.TDSExcludeRulesValidator.cs
Created October 20, 2012 06:38
BuildTasks.TDSExcludeRulesValidator / MSBuild Task for monitoring the Exclude Rules in a Sitecore TDS Project file.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@janhebnes
janhebnes / gist:3550920
Created August 31, 2012 09:43
Sitecore CMS - Handling Item copying where DataSources are referenced inside the copied structure, to inserted in the Item:Copied event queue.
/// <summary>
/// Class used to update Spot Context Data, when copying trees in Sitecore.
/// </summary>
public class LayoutDataSourceReferenceUpdater
{
#region Properties
/// <summary>
/// Gets or sets the new root Item (source item).
/// </summary>
@janhebnes
janhebnes / gist:3550905
Created August 31, 2012 09:41
Sitecore CMS - Event for handling changing the DataSources from path information to GUIDs to be inserted in the item:saving event prior to the save event
/// <summary>
/// The layout data sources are saved with a text path and not a guid.
/// </summary>
public class EnsureDataSourceIsGUID
{
public void OnItemSaving(object sender, EventArgs args)
{
Sitecore.Diagnostics.Log.Info("Running EnsureDataSourceIsGUID", this);
Item item = Event.ExtractParameter(args, 0) as Item;
@janhebnes
janhebnes / gist:3550889
Created August 31, 2012 09:39
Sitecore does not implement hard validation on the language write access at field level, so to make sure a local editor would never be able to mingle with a language he did not have access to, we added the restriction code to the Item:Saving event queue p
public class EnsureLanguageWriteAccess
{
protected void OnItemSaving(object sender, EventArgs args)
{
Item item = Event.ExtractParameter(args, 0) as Item;
Error.AssertNotNull(item, "No item in parameters");
var itemlang = item.Database.GetItem(string.Format("/sitecore/system/Languages/{0}", item.Language));
if (itemlang != null && Sitecore.Security.AccessControl.AuthorizationManager.IsDenied(itemlang
, Sitecore.Security.AccessControl.AccessRight.LanguageWrite