Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
mattbrailsford / ContentExtensions.cs
Last active March 23, 2021 16:57
Converts an IContent element to IPublishedContent in Umbraco v8
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Strings;
using Umbraco.Web.Composing;
@secretorange
secretorange / ConditionalAnchorTagHelper.cs
Last active February 17, 2019 16:23
ASP.NET 5 Conditional Anchor Tag Helper. This tag helper will omit the anchor tag if the href is null or empty.
namespace SecretOrange
{
[HtmlTargetElement("a", Attributes = "asp-conditional")]
public class ConditionalAnchorTagHelper : TagHelper
{
public override async void Process(TagHelperContext context, TagHelperOutput output)
{
var href = context.AllAttributes["href"]?.Value.ToString();
if (String.IsNullOrWhiteSpace(href))
@warrenbuckley
warrenbuckley / SomeTreeController.cs
Last active October 28, 2016 09:39
This is a way to determine what version of Umbraco is being used & conditionally change Angular views or logic based on that.
public static bool UseLegacyEditors()
{
return UmbracoVersion.Current < new Version(7, 4);
}
var someRoutePath = Core.Configuration.UseLegacyEditors()
? "/myApp/treeAlias/edit-legacy/" + someObj.Id
: "/myApp/treeAlias/edit/" + someObj.Id;
DELETE FROM umbracoUser2NodeNotify WHERE umbracoUser2NodeNotify.nodeId IN (SELECT TB1.nodeId FROM umbracoUser2NodeNotify as TB1 INNER JOIN umbracoNode as TB2 ON TB1.nodeId = TB2.id WHERE TB2.trashed = '1' AND TB2.nodeObjectType = 'c66ba18e-eaf3-4cff-8a22-41b16d66a972')
DELETE FROM umbracoUser2NodePermission WHERE umbracoUser2NodePermission.nodeId IN (SELECT TB1.nodeId FROM umbracoUser2NodePermission as TB1 INNER JOIN umbracoNode as TB2 ON TB1.nodeId = TB2.id WHERE TB2.trashed = '1' AND TB2.nodeObjectType = 'c66ba18e-eaf3-4cff-8a22-41b16d66a972')
DELETE FROM umbracoAccessRule WHERE umbracoAccessRule.accessId IN (
SELECT TB1.id FROM umbracoAccess as TB1
INNER JOIN umbracoNode as TB2 ON TB1.nodeId = TB2.id
WHERE TB2.trashed = '1' AND TB2.nodeObjectType = 'c66ba18e-eaf3-4cff-8a22-41b16d66a972')
DELETE FROM umbracoAccess WHERE umbracoAccess.nodeId IN (SELECT TB1.nodeId FROM umbracoAccess as TB1 INNER JOIN umbracoNode as TB2 ON TB1.nodeId = TB2.id WHERE TB
@davidebbo
davidebbo / AzureAutoSettings.cs
Created September 13, 2015 21:42
AzureAutoSettings
using System;
using System.Collections;
using System.Configuration;
using System.Reflection;
using System.Web;
[assembly: PreApplicationStartMethod(typeof(EnvSettings.SettingsProcessor), "Start")]
namespace EnvSettings
{
@hmemcpy
hmemcpy / undef.md
Last active November 21, 2023 16:46
Disabling Visual Studio Git Provider

Here's how to disable the package that is responsible for loading the Git source control support in Visual Studio. Use at your own risk!

  • Create a file called devenv.pkgundef and place it next to devenv.exe in you Visual Studio's Common7\IDE (you'll need elevation for this)
  • Add the following entries to the file:
[$RootKey$\Packages\{7fe30a77-37f9-4cf2-83dd-96b207028e1b}]
[$RootKey$\SourceControlProviders\{11b8e6d7-c08b-4385-b321-321078cdd1f8}]
  • Close VS if open, open a Developer command prompt, and type devenv /updateconfiguration
@sitereactor
sitereactor / MediaEventHandler.cs
Last active July 12, 2023 02:33
Renaming an image when its uploaded to a property with Alias "umbracoFile", but before its saved. The name of the image will be changed to the name of the folder it resides in. This is using the Saving event in the MediaService in Umbraco.
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.IO;
using Umbraco.Core.Services;
namespace Startup
{
public class MediaEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
@sniffdk
sniffdk / checksize
Last active February 22, 2018 08:19 — forked from anonymous/gist:1391040
declare @RowCount int, @tablename varchar(100)
declare @Tables table (
PK int IDENTITY(1,1),
tablename varchar(100),
processed bit
)
INSERT into @Tables (tablename)
SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_NAME not like 'dt%' order by TABLE_NAME asc
declare @Space table (
name varchar(100), rows nvarchar(100), reserved varchar(100), data varchar(100), index_size varchar(100), unused varchar(100)
public class Args : Dictionary<string,object>{}
public class MyIoc
{
private Dictionary<Type, Dictionary<string, Func<Args, object>>> _registry
= new Dictionary<Type, Dictionary<string, Func<Args, object>>>();
public void Register<T>(Func<Args, T> factory, string name = "") where T : class
{
Type t = typeof(T);
@kipusoep
kipusoep / web.config.xml
Last active February 26, 2024 17:08
SEO redirects for web.config
<!-- SEO rules (from: http://www.seomoz.org/blog/what-every-seo-should-know-about-iis#chaining) -->
<!-- SEO | Section 1 | Whitelist -->
<rule name="Whitelist - Resources" stopProcessing="true">
<match url="^(?:css/|scripts/|images/|install/|config/|umbraco/|umbraco_client/|base/|webresource\.axd|scriptresource\.axd|__browserLink|[^/]*/arterySignalR/.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<!-- SEO | Section 2 | Rewrites (chaining) -->
<rule name="SEO - Remove default.aspx" stopProcessing="false">
<match url="(.*?)/?default\.aspx$" />