Use Contentstack to power content for your .NET projects

Create .NET-based applications and use the .NET SDK to fetch and deliver content from Contentstack. The .NET SDK uses the Content Delivery APIs.

Getting Started

This guide will help you get started with our .NET SDK to build apps powered by Contentstack.

SDK Installation and Setup

Contentstack offers two regions (US and European) as data centers to store customers' account details and data. Both regions are independent of each other and therefore has a dedicated set of instructions to use SDKs offered by Contentstack.

To use SDKs for the European region, you will have to make certain changes in the configuration of the SDK, as detailed below, and the rest of the instructions remain the same.

Open the terminal and install the contentstack module via ‘Package Manager’ command:

PM> Install-Package contentstack.csharp

And via ‘.Net CLI’

dotnet add package contentstack.csharp

To use the module in your application, you need to first Add Namespace to your class

using Contentstack.Core; // ContentstackClient
using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType
using Contentstack.Core.Configuration; // ContentstackOptions

Initialize SDK

You will need to specify the API key, Delivery token, and Environment Name of your stack to initialize the SDK:

// Initialize the Contentstack
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment_name");


var options = new ContentstackOptions() {
    ApiKey = "<api_key>",
    AccessToken = "<delivery_token>",
    Environment = "<environment>"
ContentstackClient stack = new ContentstackClient(options);

For Setting the European Region:

ContentstackOptions options = new ContentstackOptions() {
    ApiKey = "<api_key>",
    AccessToken = "<delivery_token>",
    Environment = "",
    Region = ContentstackRegion.EU
ContentstackClient stack = new ContentstackClient(options);</delivery_token></api_key>

Once you have initialized the SDK, you can start getting content in your app.

Basic Queries

Get a Single Entry

To retrieve a single entry from a content type, use the code snippet given below:

Entry entry = client.ContentType("blog").Entry("blta464e9fbd048668c");
entry.Fetch<Blog>().ContinueWith((t) => { 
    if (!t.IsFaulted) { 
        Console.WriteLine("entry:" + t.Result);  

Get Multiple Entries

To retrieve multiple entries of a particular content type, use the code snippet given below:

Query query = client.ContentType("blog").Query(); 
query.Where("title", "welcome"); 
query.Find<Blog>().ContinueWith((t) => { 
    if (!t.IsFaulted) { 
         ContentstackCollection<Blog> result = t.Result; 
         Console.WriteLine("result" + result); 

These were example of some of the basic queries of the SDK. For advanced queries, refer to our API reference documentation by visiting the link given below.

API Reference

Go through our .NET SDK API Reference guide to know about the methods that can be used to query your content in Contentstack.

Read .NET API Reference Guide

Example App

To help you get started, we have created a sample console application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app.

Was this article helpful?