Logo
Logo
  • Blazor CMS Home
  • Oqtane Tutorials
  • Blazor CMS Home
  • Oqtane Tutorials
Oqtane Tutorials
Oqtane Tutorials

External Data from CSV or SQL

Tutorial Home › External Data
Look at the Content-Type of something
#1 Example from CSV
Various SQL Samples
The samples can differ based on your Razor base class or if you're running an old version.
Switch to Strong-Typed (2sxc 17.06+) Selected: Typed (2sxc 16+) Switch to Dynamic (Razor14 or below)
Requirements
  • 2sxc 06.05
Resources
  • Query Params
  • CsvDatasourceDocs

Example from CSV

CSV files are often used so website-owners can upload data from another system. This example shows us getting the CSV-file through a query and visualizing it here.

Result

  • 2sxc (#1)
  • Image Resizer (#4)
    Automatic, amazing image Resizer (find out more)
  • Koi (#2)
  • Razor Blade (#3)
@inherits Custom.Hybrid.RazorTyped
@using ToSic.Razor.Blade
@using System.Linq

@{
  // get the query
  var query = Kit.Data.GetQuery("ProductsFromCSV");

  // get the data from the query
  var products = AsItems(query);

  // get the current product or the default - the query always selects one
  var current = AsItem(query.GetStream("Current"));
}
<ul>
  @foreach (var product in products) {
    <!-- this li will have class=selected if it's the current one -->
    <li class='@(product.Equals(current) ? "selected" : "")'>
      <!-- this creates a link to the current page and product=id -->
      <a href='@Link.To(parameters: MyPage.Parameters.Set("product", product.Id.ToString()))'>
        @product.Get("Name") (#@product.Id)
      </a>
      @if (product.Equals(current)) {
        <br>
        <em>
          @current.Get("Description") 
          (<a href="@product.("Link")" target="_blank">find out more</a>)
        </em>
      }
    </li>
  }
</ul>

Source Code of products.csv.txt

Id;Name;Description;License;Created;Link
1;2sxc;A neat CMS extension for DNN;MIT;01.01.2012;https://2sxc.org/
2;Koi;System to coordinate the CSS-Framework between theme and modules. ;MIT;01.06.2018;https://connect-koi.net/
3;Razor Blade;Helpers for common Razor task;MIT;01.02.2019;https://github.com/DNN-Connect/razor-blade
4;Image Resizer;Automatic, amazing image Resizer;MIT;06.05.2013;https://2sxc.org/learn-extensions/ImageResizer

View Configuration

This is how this view would be configured for this sample.

  • Query: ProductsFromCSVOqtane

No details yet for ProductsFromCSVOqtane

This is similar to the previous example, except that the CSV file can be uploaded again and again in the App-Settings UI. So the path isn't hard-coded.

Result

  • 2sxc (#1)
  • Image Resizer (#4)
    Automatic, amazing image Resizer (find out more)
  • Koi (#2)
  • Razor Blade (#3)
@inherits Custom.Hybrid.RazorTyped
@using ToSic.Razor.Blade
@using System.Linq

@{
  // get the query
  var query = Kit.Data.GetQuery("ProductsFromCsvInAppSettings");

  // get the data from the query
  var products = AsItems(query);

  // get the current author (if available) from the stream Current
  var current = AsItem(query.GetStream("Current"));
}
<ul>
  @foreach (var product in products) {
    <!-- this li will have class=selected if it's the current one -->
    <li class='@(product.Equals(current) ? "selected" : "")'>
      <!-- this creates a link to the current page and product=id -->
      <a href='@Link.To(parameters: MyPage.Parameters.Set("product", product.Id.ToString()))'>
        @product.Get("Name") (#@product.Id)
      </a>
      @if (product.Equals(current)) {
        <br>
        <em>
          @current.Get("Description") 
          (<a href="@product.Url("Link")" target="_blank">find out more</a>)
        </em>
      }
    </li>
  }
</ul>

Source Code of products.csv.txt

Id;Name;Description;License;Created;Link
1;2sxc;A neat CMS extension for DNN;MIT;01.01.2012;https://2sxc.org/
2;Koi;System to coordinate the CSS-Framework between theme and modules. ;MIT;01.06.2018;https://connect-koi.net/
3;Razor Blade;Helpers for common Razor task;MIT;01.02.2019;https://github.com/DNN-Connect/razor-blade
4;Image Resizer;Automatic, amazing image Resizer;MIT;06.05.2013;https://2sxc.org/learn-extensions/ImageResizer

View Configuration

This is how this view would be configured for this sample.

  • Query: ProductsFromCSVOqtane

No details yet for ProductsFromCSVOqtane

 

Look at the Content-Type of something
#1 Example from CSV
Various SQL Samples
  • 2sic internet solutions
  • Langäulistrasse 62, 9470 Buchs SG, Switzerland
  • +41 81 750 67 77
Login