#2 Get DataSources in Code - Basics
Data Sources Tutorial - Basic Use
Requirements
To get started, let's look at some samples to just use a DataSource in code.
First Sample: Get Csv DataSource using Kit.Data
Use Kit.Data.GetSource<Csv>
to create a DataSource reading CSV data.
This sample shows how to:
- Use
Kit.Data.GetSource<DataSourceName<
to get the desired DataSource - Get a
Csv
DataSource fromToSic.Eav.DataSources
- When creating the source, also provide settings for
FilePath
andDelimiter
- Loop through the items
List of Data in the CSV DataSource (4)
- 2sxc (A neat CMS extension for DNN)
- Koi (System to coordinate the CSS-Framework between theme and modules.)
- Razor Blade (Helpers for common Razor task)
- Image Resizer (Automatic, amazing image Resizer)
#2 Get DataSources in Code - Basics
Source Code of this file
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade; @using System.Linq; @using ToSic.Eav.DataSources; <!-- unimportant stuff, hidden --> <h2>Data Sources Tutorial - Basic Use</h2> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <p> To get started, let's look at some samples to just <em>use</em> a DataSource in code. </p> </div> </div> First Sample: Get Csv DataSource using... <!-- unimportant stuff, hidden --> @{ // Create the data source and provide configuration in the options var products = Kit.Data.GetSource<Csv>(parameters: new { FilePath = App.RelativePath + "/data-sources-use/assets/products.csv.txt", Delimiter = ";", }); } <h3>List of Data in the CSV DataSource (@products.List.Count())</h3> <ul> @foreach (var product in AsList(products)) { <li> @product.Name (@product.Description) </li> } </ul> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })