Useful C# 6.0 features

There are alot of new features in C# 6.0, some of them might help you write cleaner code in less time. Let’s have a look at two of the (in my opinion) best features:

Interpolated Strings
We have all been there.. concatenating strings usings tons of “+” or using String.Format, just to use some kind of placeholders. Interpolated strings are a neat way to get rid of that.

Employee emp = new Employee();
emp.Firstname = "John";
emp.Lastname = "Doe";

//enable the interpolated string by using a $ prefix
Console.WriteLine($"Firstname: { emp.Firstname }, Lastname { emp.Lastname }");

Null-conditional operator
Checking for a null value in a complex type before accessing its properties is a common task. Unfortunately, this requires a few lines of code. C# 6.0 introduces null-conditional operators.


string result = null;

//conventional...
if (p.Address.Street != null)
{
  result = p.Address.Street;
}
else
{
 result = "default value";
}

//null-conditional operator
result = p.Address?.Street ?? "default value";

Nice, isn’t it? Happy coding!

Advertisements
Useful C# 6.0 features

SharePoint 2013: How to delete a drop-off library

A drop-off library is a useful SharePoint feature when it comes to content organization, automatic tagging and stuff like that. However, once enabled, it’s not possible to delete a drop-off library in the library settings. But it’s easy to flag this library as deletable via powershell. Deactivate the corresponding site feature first.


$web = Get-SPWeb https://yoursite.com/site
$list = $web.Lists["Abgabebibliothek"] 
$list.AllowDeletion = $true
$list.Update()

Make sure the name of the list matches your selected site language ([“Drop Off Library”] or [“Abgabebibliothek”]).

SharePoint 2013: How to delete a drop-off library

Visual Studio 2015: Backspace not working

This bug seems to keep annoying us in Visual Studio 2015: From time to time, some keys (e.g. backspace!) stop working all of a sudden. The only way to get around this behaviour is to reopen the current document or to restart Visual Studio. But there’s an easy work-around! Just press Alt+Enter to reset the focus on the current document and you’re fine. It’s as easy as that!

Visual Studio 2015: Backspace not working

SharePoint Online – where’s the “Page Layouts and site templates” option?

I was wondering where to find the “Page layouts and site templates” option in a standard SharePoint Online tenant. Actually i don’t know why the guys in Redmond are hiding this option in the site settings, but it’s still available using a direct link:

yoururl.sharepoint.com/_Layouts/AreaTemplateSettings.aspx

SharePoint Online – where’s the “Page Layouts and site templates” option?

SharePoint 2013: custom masterpage elements showing up in dialog box

I tried to include a custom header in a standard SharePoint 2013 masterpage (“Seattle”), unfortunately, the new content header was showing up in every dialog box too. I found a quick and easy work-around to prevent the custom code from being rendered. Just wrap the whole custom code in a div tag and add a class called “s4-notdlg” to that div – works like a charm!

<div class="s4-notdlg">   
..custom code...  
</div>
SharePoint 2013: custom masterpage elements showing up in dialog box

SharePoint 2013: Can’t open Excel Workbook in Web Part

If you ever run into an error like “Excel could not open the workbook” or something similar, make sure to grant your managed account access to the content database!

Run the Management Shell as an administrator and run the following commands:

$w = Get-SPWebApplication -identity http://yourwebapplication
$w.GrantAccessToProcessIdentity("DomainUser")

This solution was originally posted on http://technet.microsoft.com/en-us/library/jj219698.aspx but i spent a good amount of time to find it – so let’s repost it! 🙂

SharePoint 2013: Can’t open Excel Workbook in Web Part

IIS 8 Error 500.19 – duplicate MIME type entries

If you have to move an asp.net application from an IIS 7.5 to an IIS 8.0 server, you might run into problems with a 500.19 error. The reason for this is the fact, that in IIS 8.0, most well-known MIME types are being registered on a server level. So if you had to add a specific MIME type in your web.config in IIS 7.5 (for example “svg”, chances are good that this type is already predefined and inherited by your site.

Remove the corresponding line in your web.config and restart your site! It should be working now.

IIS 8 Error 500.19 – duplicate MIME type entries