Thursday, July 16, 2015
Saturday, July 4, 2015
Visual Studio - Resharper Code Snippet for Method
It
have bugged med a lot lately that there is no default method template snippet
in Visual studio.
How
this can even be is beyond me, but I found a neat solution:
In
Template Manager in Resharper you can easily add this method yourself. Here:
Click
create New Template in the Templates Explorer.
This will add a strange file in the background that
you can edit and it has No Name as default this name is to be replaced with
your snippet name. So just fill in the Shortcut: box to the right.
And add the code into the template and save.
This is the code for a simple method snippet with
changeable return type:
Now within a class just type method
Saturday, June 27, 2015
Powershell - Run Process as Administrator
Example:
Start-Process powershell_ise -verb runas
Friday, June 26, 2015
C# - Get Web.config Variable Value
Example value in web.config:
<appSettings>
<add key="ClientId" value="123"/>
<add key ="webUrl" value="http://www.nasa.gov/"/>
</appSettings>
C# Get:
using System.Configuration;
string ClientId=ConfigurationManager.AppSettings["ClientId"]
string webUrl=ConfigurationManager.AppSettings["webUrl"]
Jadda jadda null check on string ClientId and webUrl.
Monday, June 8, 2015
C# - Stripping all html from string fast!
Code example:
/// <summary>
/// Compiled regular expression for performance.
/// </summary>
static Regex _htmlRegex = new Regex(@"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", RegexOptions.Compiled); Alternavtive regex = static Regex _htmlRegex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Compiled);
/// <summary>
/// Remove HTML from string with compiled Regex.
/// </summary>
public static string StripTagsRegexCompiled(string source)
{
return _htmlRegex.Replace(source, string.Empty);
}
Wednesday, May 27, 2015
EPiServer 7.5 - EPiServer.UI.Admin.SiteMgmt Missing
In
EPiServer 7.5, the namespace EPiServer.UI.Admin.SiteMgmt has been removed and
site & host management now being implemented with SiteDefinitionRepository
and SiteDefinition.Current.
Example Code:
Example Code:
In EPiServer < 7.1
Get sites
var sites = SiteInformationHandler.GetSitesInformation(true);
Get Host:
var hosts = SiteInformationHandler.GetSiteInformation(this.SiteID, true);
In EPiServer > 7.5
Get sites
var siteDefinitionRepository = ServiceLocator.Current.GetInstance<SiteDefinitionRepository>();
var sites = siteDefinitionRepository.List().ToList();
Get Host:
var hosts = SiteDefinition.Current;
Subscribe to:
Posts (Atom)

