Injecting resource files as plain JavaScript objects in ASP.NET Core

Localization and internationalization are much-discussed topics and many terrific solutions have been developed to easily create multilingual applications. I would like to introduce a different way of localizing web-based applications. As the title suggests, I will show you how to inject resource files as plain JavaScript objects to the web client. The result is a simple JavaScript object which is globally available to the client. I found this so useful that I did a similar thing for translated content and even the application’s settings (which are stored in a database).

Exam 70-487 Preparation: the review

Over the last few weeks, I made a few blog posts containing useful links for Microsoft’s certification exam 70-487: Developing Microsoft Azure and Web Services. I’m pleased to announce that I passed the exam with a score of 873. And because this is the third exam in the MCSD Web Applications track, I am now also a certified Microsoft Certified Solutions Developer.

Create lambda expressions on the fly in C#

For the last couple of weeks I have been working with client-side frameworks such as Kendo UI and Sencha ExtJS a lot. One of the requirements of my clients was server-side filtering, grouping and ordering of several grids and other components. The challenge here is that you don’t know exactly what information might be coming in: which field do you have to filter or sort, which direction, what operator do you have to use, etc. There is only one proper way to do this in C#: Expressions.

ASP.NET MVC fixing error ‘Multiple types were found that match the controller named’ when routing is not the problem

I just came across following error message while I was converting one of my ASP.NET MVC applications:

Multiple types were found that match the controller named 'Home'. 

How to prepare for Microsoft exam 70-483 programming in C#

Today I passed the 70-483 Programming in C# exam. As any other Microsoft exam, the passing score is 700 on a total score of 1000. I scored way above my expectations, so I’m very happy that my efforts are rewarded with a MCP certificate. I can highly recommended experienced consultants and developers to take this exam. For beginning programmers ( < 1 year) this exam will probably be too difficult as there are many topics in scope of the exam. In order to motivate anyone who wants to take this exam, here is how I experienced the exam.

Managing shared information with IDisposable in C# and SharePoint

Every once in a while you’ll have a situation in which you temporarily have to use different (shared) settings and reset them if all work is done. An example of this is often seen in SharePoint, for instance disabling events when updating items in event receivers, or allowing unsafe updates. A workaround that I have seen a lot is that developers add a TRY/CATCH/FINAL block for each method they want to reset some objects. In this post, I’ll talk about an alternative way of achieving this behavior by the implementation if the IDisposable interface.

Writing the output from console applications to text file

Console applications provide a quick and easy way (and also a little bit dirty) to test or fix parts of your application. It enables you to focus on the business logic rather than the GUI. Sometimes the output to the window is quite large – larger than the console window can show. In those cases you want to be able to persist the output to text files. In this post, I’ll show you how to do this.

Real-time applications with SignalR and SQLDependency in ASP.NET MVC

In one of my previous posts, I talked about using SQLDependency as a mechanism for detecting triggers on certain SQL queries. In this post, I’ll talk about how to use this mechanism to display real-time data in web applications using SignalR.

Item-based exception handling in LINQ

Last week I rewrote some of my client’s code after having discovered a number of bugs. More specifically, a lot of errors came up in LINQ methods such as Where and Select. In order to capture what exactly was going wrong there, I have added a new extension method to the IEnumerable interface, allowing item-based exception handling on collections and LINQ statements.

Developing timerjobs in C# with Quartz.NET

At some point, any developer will have to write some code that must be executed at regular intervals. In SharePoint for instance, timerjobs were (!) very easy to create. In .NET, you could choose between scheduled tasks and windows services. While I was doing research on the ideal replacement for timerjobs in the new SharePoint app model, I came across Quartz.NET. In this post, I will show you which code you need to create timerjobs.

Retrieving blog posts using C# and the WordPress REST API

There are a few ways in which you can integrate your website or application with social media or other websites. Perhaps the easiest and most used way are the widgets or embedded HTML snippets. The Twitter embedded timeline is arguably the most famous example. It’s easy to use and doesn’t require much (if any) programming skills. It provides a familiar user experience that people know from using other websites. In many cases this is just what you need, but what if you wanted to make it look and feel like any other part of your website? In this post I will show you way of doing just that with WordPress blog posts.

C# trigger after database changes with SQLDependency

I found the following amazing article with some code that works without any modifications. With SQLDependency, you can listen to database changes with a predefined query. If something happens to this result set (INSERT/DELETE/UPDATE) an event will be triggered, allowing you to take action.

Tutorial on creating loosely coupled applications with MEF

When I first read about MEF (Managed Extensibility Framework), I thought it was a great concept to create plugin-based applications, allowing customers to customize some behavior of the application for instance. Putting the whole concept into reality is something different, so in this article I will give a brief overview of the steps to take to get started with MEF.

Creating SQL schemas using Entity Framework Code First

As you might have read in my previous post, I used SQL schemas to partition data between tenants. Being part of the true definition of SaaS, a new tenant should be up and running within minutes without any human intervention. With my suggested approach, we need to do two things:

  • Registering a new tenant
  • Attaching users to the tenant

In this article, I am going to focus on the first item whereas the second one shouldn’t be a big deal if you are planning to create software as a service.

Multi-tenancy with ASP.NET MVC and Entity Framework

Until recently I have never had the time to concentrate on cloud application development. All of the projects (non-SharePoint related) I have ever worked on were dedicated to only one customer, so the multi tenancy challenge never came up. Although my own website is hosted on Azure, I realized I had to create my own project to gain some knowledge on this area. There are many books and web pages available regarding cloud development, but for a very good reason none of those give really specific examples: it all depends on what you want to achieve. In this article, I will cover one scenario that is quickly to implement with the knowledge many .NET developers probably still have, which is developing a **ASP.NET MVC application with Entity Framework which ensures storage in one database with multiple schemas.

Parallel looping and returning 1 collection in C#

An interesting feature in .NET 4.5 is the ability to process collection in parallel. Along with the async/await feature, you can really improve the performance of your application with a few simple steps. Whereas both components are documented really well, I thought this would be a walk in the park. However, you should pay attention when you want to return a collection that was modified in the parallel block. If you don’t, you might be missing a few items in the list.

C# and the Spotify Web Api: part I (authorization)

Curious about the possibility of displaying Spotify playlists on my website, I investigated the Spotify Web API. Initially, I thought everything seemed quite easy, but then I got to the authentication and authorization section. As it turned out, it is not that simple but after trial and error, I got what I wanted. Here’s what I did.

Repository pattern in SharePoint

A few months ago, I had an assignment for a multinational beverage company to implement a publication system for their products across Europe. Along with a few other consultants and managers from another unit in my company, they had decided to go for a SharePoint solution as this seemed to meet all business requirements: centralized master data management with the ability to generate XML – and Word (or other human friendly) documents. I got on the project a few months later only to discover that the suggested approach could never work: the entire data model (entirely relational and normalized) was made with many SharePoint lists and the data was retrieved with JSOM. With a limited budget and a tight deadline, the best thing to do was to make a proper design with a solid architecture and minimal amount of code and complexity. The best alternative here was to build a custom SharePoint solution with a custom ORM layer. I considered LINQ 2 SharePoint but in this project where nothing was certain and everything changed rapidly, I quickly decided that a custom ORM layer was the most suitable. If I had the choice to start from scratch, I definitively would have chosen to go for the combination EF + BCS. As this MSDN article explains, the repository pattern is pretty much the way to go when it comes to building a generic, high quality and lightweight data access layer. This also counts for SharePoint solutions, as Chris O’Brien confirms in an old article. Although many articles cover this topic, I never was quite satisfied with the technical solution that was provided.

In what follows is a very simple yet powerful way of creating a generic data access layer for SharePoint (both CSOM and SSOM).