SharePoint 2013: Accessing TermStore with C#

In this blog I’m going to talk about how to access the TermStore with C# and how to add, update and delete a term. I’m going to use some code from my previous post on how to connect to SharePoint. Now let us jump right in. How do I access the TermStore? Accessing it isn’t that hard. First, you’ll need additionally to the other dlls the Microsoft.SharePoint.Client.Runtime.dll

Continue reading

CleanCode Part 2: Comments and Unit tests

In this second post about CleanCode I’m going to talk about Comments and Unit tests. Explain yourself in code. This means you should choose your names and variables that no comments are needed. If you have the feeling that you should comment a code fragment because it isn’t understandable you probably should rewrite the code instead of commenting it. There are situations you’ll need to write a comment for clarification or to explain something. For example with date calculating. Some methods give January as 1 back and other methods as 0. SO have to subtract or add to get the right format. One of the most important comments are the TODO comments. Like this you can mark code which still needs work to finish. VisualStudio helps you by showing all TODO Comments in the task list. There are some mistakes you can make while writing comments. Don’t write redundant comments. It may be that you code reads itself better than the comment which just says the same. If that is the case just leave it away. Don’t write to much comments it just clutter up the code and often will be over read because it just takes too much time to read through all of them. You also can comment code but this isn’t a good practice. Most of the time you qill forget about the code you commented out. So the rule is out commented code is not allowed. Only exception if you have TODO over the out commented code.

Continue reading

Accessing SharePoint Data with C#

Accessing SharePoint Data with C# is easy but a bit annoying. First of all you’ll need two extensions to be able to connect to SharePoint.

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

Both of these extension can be found in Visual Studio in the Reference Manager under Extensions. A site is loaded as a ClientContext. From there you have access to all lists, sites and properties. I’ve made a method which helps me to initialize a context. Continue reading

CleanCode Part 1: Meaningful names and functions

This is going to be a series of posts. On each post I’m going to talk about Clean Code. In this post I try to explain the Clean Code principles. The first principle is “Meaningful Names”. Like the title says you should choose your function names, variables names, classes names, arguments names, … with a meaning behind it. This means the name reveal its intention for example a variable named x1 is not understandable but firstCell will give you an idea what it might be. Another important thing is to try avoid disinformation. This means you shouldn’t name a group of cars “carList”. It will tell the reader that it is a list so use cars instead or carGroup. Try to use pronounceable Names. This will make it a lot easier to read the code or review it with a coworker. Let’s say you are reviewing the code with a friend and the function GetCstmr comes up. Now you will have to try to say it, instead of just saying GetCustomer.

Continue reading

WebServices, Rest service

Web Services

What is a Web Service?

A Web service is a method of communication between two electronic devices over a network. It is a software function provided at a network address over the Web with the service always on as in the concept of utility computing. The W3C defines a Web service generally as:-

A software system designed to support interoperable machine-to-machine interaction over a network. – Wikipedia.

Continue reading

Null Object Design Pattern

Null Object Design Pattern
The Null Object Pattern is a design pattern where there are no object references which are null. Instead of null it will be a Null-Object in its place. The Null-Object is a placeholder and does nothing or a default behavior. With this approach we eliminate the necessity to check for null values. This helps to keep the code short and clean. The big advantages it makes the calls of methods really simple. Let’s say you have a list of cars and you want to call drive on every car. Without the null object design pattern you would need to check every car if it is null. With the null object design pattern there is no need for the check you can treat everything equals. The Null-Object will do nothing or simply a default behavior which normally has no influence on the rest of the program. This also approach can also be used with lists. Usually it is an empty list. If you iterate through the list nothing will happen.

Continue reading

Dependency Injection

Simply said dependency Injection is a pattern where the dependencies in an object are given. This means that instead of creating the needed objects in the class itself we pass it to them. You can think of like the Hollywood principle: “Don’t call us, we call you”. The class itself won’t “call” the dependency, instead someone else will pass it to them.
Dependency Injection can be used really easy and fast. There are some very simple ways to implement it in a project. The first is the constructor injection. You probably already used this without knowing that this already is dependency injection.

Continue reading