Skip to main content
Home  ›  Blog

Using App Data Outside of 2sxc - in Razor, Custom WebApi, Skin or another Module (300)

Sometimes you want to leverage 2sxc to create a solution, provide data input etc. but want to output or re-use the data in your own Module, Skin, Script or something else. This is easy to do.

We enhanced 2sxc fairly recently to include special Constructors giving you all you need - no matter where your initial code started. The scenarios are things like

  1. Already created Razor scripts (hosted in the Razor host) which should then use some data previously collected in a 2sxc App
  2. Existing WebForms solutions which need this app data or a Visual Query previously made in 2sxc
  3. More complex server side mashups which need to merge stuff from multiple tables, 2sxc and various modules
  4. Existing stuff which you want to extend with 2sxc MetaData (more about that some other post) 

Note: if you actually want to render 2sxc content blocks with edit-functionality and everything (instead of working with the data of an App) then you want to read the blog about using the 2sxc instance.

The App Constructor

Basically all you need is to reference the 2sxc DLL and call ToSic.SexyContent.Environment.Dnn7.App(…) and you're good to go. From then on you have an App object (with interface IApp) with properties like

  • App.Data["Typename"]
  • App.Settings["Settingname"]
  • App.Resources["ResourceName"]
  • App.Query["Queryname"]
  • App.Path
  • Etc.

The C# Code (this works from any .net code)

// the app id
var appId = 42;

// create a simple app object to then access data
var appSimple = ToSic.SexyContent.Environment.Dnn7.Factory.App(appId, versioningEnabled: false);

// example getting all data of content type Tag
var tags = appSimple.Data["Tag"];

// example accessing a query
var tagsSorted = appSimple.Query["Tags sorted"];

// Creating an entity
var vals = new Dictionary<string, object>();
vals.Add("Tag", "test-tag");
vals.Add("Label", "Test Tag");

App.Data.Create("Tag", vals);


Hope you love it,

Daniel Mettler grew up in the jungles of Indonesia and is founder and CEO of 2sic internet solutions in Switzerland and Liechtenstein, an 20-head web specialist with over 800 DNN projects since 1999. He is also chief architect of 2sxc (see github), an open source module for creating attractive content and DNN Apps.

Read more posts by Daniel Mettler