Skip to content

Instantly share code, notes, and snippets.

View doeringp's full-sized avatar
🏠
Working from home

Peter Doering doeringp

🏠
Working from home
View GitHub Profile
@doeringp
doeringp / Resources.aspx.cs
Last active July 12, 2016 10:36
Make RESX files available at client-side for JavaScript.
using System;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
namespace AspNetWebFormsApp
@doeringp
doeringp / AppSettings.cs
Last active July 12, 2016 10:36
Dynamic Wrapper for the values in the ConfigurationManager.AppSettings dictionary.
using System.Configuration;
using System.Dynamic;
using System.Linq;
namespace AppSettingsDemo
{
/// <summary>
/// Wrapper for the values in the ConfigurationManager.AppSettings dictionary.
/// Declare an instance of the AppSettings class with the dynamic keyword and all calls
/// to any properties will lookup for the right key in the appSettings-section in you app.config
@doeringp
doeringp / MonitoredScope.cs
Created July 12, 2016 10:49
Time measuring for code blocks with StopWatch and NLog.
using System;
using System.Diagnostics;
using NLog;
namespace Doering.Logging
{
/// <summary>
/// Use MonitoredScope within a using statement to measure the time the operation needs.
/// The result will be written to the NLog logger.
/// </summary>
@doeringp
doeringp / Program.cs
Last active July 12, 2016 11:03
Helper class to run code in SharePoint with elevated priviliges.
using Doering.SharePoint;
class Program {
static void Main() {
// Access a list within the current web with higher privileges.
SPSecurityExtensions.RunInElevatedSite(delegate (SPSite site, SPWeb web)
{
@doeringp
doeringp / validation.js
Last active February 11, 2017 16:35
Hook into the ASP.NET client-side validation to apply some styles to the control if the validation fails.
(function($) {
if (typeof (window.ValidatorUpdateDisplay) === "undefined" || window.ValidatorUpdateDisplay == null) {
console.warn("The ValidatorUpdateDisplay() method isn't defined. Can't inject custom validation.");
} else {
var aspUpdateDisplay = window.ValidatorUpdateDisplay;
window.ValidatorUpdateDisplay = function (n) {
var $controlToValidate = $(document.getElementById(n.controltovalidate));
@doeringp
doeringp / ImageManipulation.cs
Last active March 2, 2017 08:35
Creating thumbnail images with .NET's System.Drawing classes.
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
namespace ImageManipulation
{
/// <summary>
/// Helper for manipulating images. Resizing images and creating thumbnails.
@doeringp
doeringp / MyPage.aspx.cs
Created April 27, 2017 05:33
Get the Correlation Id of the current request in SharePoint
public partial class overview : Page
{
[DllImport("advapi32.dll")]
public static extern uint EventActivityIdControl(uint controlCode, ref Guid activityId);
protected void Page_Load(object sender, EventArgs e)
{
var correlationId = new Guid();
EventActivityIdControl(1, ref correlationId);
@doeringp
doeringp / LazySample.cs
Created May 19, 2017 05:12
Lazy Loading with the Lazy class
private static readonly Lazy<string> _packagePhysicalPath = new Lazy<string>(ResolvePackagePath);
public static string PackagePhysicalPath
{
get
{
return _packagePhysicalPath.Value;
}
}
@doeringp
doeringp / Script.ps1
Created October 25, 2017 11:06
PowerShell: Waiting for an action to complete
do {
Write-Host "." -NoNewline
Start-Sleep -Seconds 3
} until (Get-HotFix -Id KB2693643 -ErrorAction SilentlyContinue)
@doeringp
doeringp / Startup.cs
Created January 24, 2018 14:11
Challenge authentication using a custom middleware (no mvc).
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.IdentityModel.Tokens.Jwt;
namespace AspNetCoreAuthTest
{
public class Startup