Skip to content

Instantly share code, notes, and snippets.

View mikaelnet's full-sized avatar

Mikael Högberg mikaelnet

View GitHub Profile
public static class GuidUtils
{
/// <summary>
/// Creates a name-based UUID using the algorithm from RFC 4122 §4.3, using SHA1
/// (version 5). This is useful for creating predictive Guid based on content.
/// </summary>
/// <param name="namespaceId">A known namespace to create the UUID within</param>
/// <param name="name">The name (within the given namespace) to make the Guid from</param>
/// <returns></returns>
public static Guid Create(Guid namespaceId, string name)
@mikaelnet
mikaelnet / invalid-chars-in-sitecore-fields.sql
Created November 26, 2019 15:34
Finds invalid characters in any Sitecore field
SELECT * FROM (
SELECT ItemId, FieldId, Value FROM [SharedFields] (nolock)
UNION
SELECT ItemId, FieldId, Value FROM [UnversionedFields] (nolock)
UNION
SELECT ItemId, FieldId, Value FROM [VersionedFields] (nolock)
) A
WHERE Value Like '%' + CHAR(0x01) + '%'
OR Value Like '%' + CHAR(0x08) + '%'
OR Value Like '%' + CHAR(0x10) + '%'
@mikaelnet
mikaelnet / Sitecore-InvalidContentFieldData.sql
Last active November 2, 2022 00:47
Finds invalid content in the Sitecore database
DECLARE @SharedFieldId UniqueIdentifier = '{BE351A73-FCB0-4213-93FA-C302D8AB4F51}' /* Shared checkbox */
DECLARE @UnversionedFieldId UniqueIdentifier = '{39847666-389D-409B-95BD-F2016F11EED5}' /* unversioned checkbox */
DECLARE @TemplateFieldId UniqueIdentifier = '{455A3E98-A627-4B40-8035-E683A0331AC7}' /* Template field */
-- Find all templates WHERE both "Unversioned" AND "Shared" is selected:
-- "Shared" will have precedense, so the "Unversioned" checkbox can be removed
SELECT * FROM SharedFields
WHERE FieldId=@UnversionedFieldId AND [Value] = '1'
AND ItemId IN (SELECT ItemId FROM SharedFields WHERE FieldId=@SharedFieldId AND [Value]='1')
@mikaelnet
mikaelnet / FilteredSitecoreItemCrawler.cs
Last active May 10, 2020 07:54
Sitecore Filtered Item Crawler
using System;
using System.Collections.Generic;
using System.Linq;
using Sitecore;
using Sitecore.Collections;
using Sitecore.ContentSearch;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
@mikaelnet
mikaelnet / Broken links Report.ps1
Created August 21, 2019 12:31
Updated Sitecore SPE Broken links Report
@mikaelnet
mikaelnet / TouchItem.cs
Created April 15, 2019 14:23
Sitecore Touch-Item Powershell Cmdlet
using System.Management.Automation;
using Sitecore.Data.Items;
[OutputType(typeof(Item)), Cmdlet("Touch", "Item")]
public class TouchItem : Cmdlet
{
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public Item Item { get; set; }
protected override void ProcessRecord()
@mikaelnet
mikaelnet / find-text-in-database.sql
Created April 5, 2016 07:01
Find a piece of text in any column in any table in a SQL Server database
DECLARE @SearchStr nvarchar (100)
SET @SearchStr = 'string to find'
CREATE TABLE #Results ( ColumnName nvarchar( 370), ColumnValue nvarchar(3630 ))
SET NOCOUNT ON
DECLARE @TableName nvarchar (256), @ColumnName nvarchar( 128), @SearchStr2 nvarchar(110 )
SET @TableName = ''
SET @SearchStr2 = QUOTENAME( '%' + @SearchStr + '%','''' )
@mikaelnet
mikaelnet / table-sizes.sql
Created April 4, 2016 09:41
List the size of all tables in database on SQL Server
select 'Database Name: ', db_name()
set nocount on
if exists(select name from tempdb..sysobjects where name='##tmp') drop table ##tmp
create table ##tmp(nam varchar(50), rows int, res varchar(15),data varchar(15),ind_sze varchar(15),unsed varchar(15))
go
declare @tblname varchar(50)
declare tblname CURSOR for select name from sysobjects where xtype='U'
open tblname
Fetch next from tblname into @tblname
WHILE @@FETCH_STATUS = 0
@mikaelnet
mikaelnet / Upload-MediaItems.ps1
Created November 19, 2015 07:31
Sitecore Powershell Image upload
function Update-MediaItem {
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string]$filePath,
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$mediaPath)
@mikaelnet
mikaelnet / LevenshteinDistanceComputer
Created April 17, 2015 08:28
Computes Levenshtein Distance of two strings
public static class LevenshteinDistanceComputer
{
public static int LevenshteinDistance(this string s, string t)
{
return Compute(s, t);
}
public static int Compute(string s, string t)
{
if (string.IsNullOrEmpty(s))