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.

Replacing file extensions from uppercase to lowercase

Here’s a very simple utility that recursively finds uppercase file extensions and makes those who are lowercase. For once, it’s not written in C# but in good old DOS. If you paste this code in a CMD file, you’ll have a working program. If you execute this cmd, it will take the current folder as the root and it will process all files and subfolders.

Nowadays you would use PowerShell but this is a way to provide a quick fix to your users.

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).