Requirements
Resources
Initial Code
The following code runs at the beginning and creates some variables/services used in the following samples.
Files from the current Portal
Output
- Last Continent.png
- photo-1651590814269-ccf8dee671ae.jpg
- ed hardy.png
- Resize and crop with presets.png
- settings-stack.svg
- image.png
- Per Anhalter.jpg
- Per Anhalter-1.jpg
- content-templates.svg
- good omens.png
Files from the root portal
Output
- boris-baldinger-eUFfY6cwjSU-unsplash.jpg
- Demo-1.jpg
- Demo-2.jpg
- Demo-3.jpg
- hugo-fergusson-xtQidmET07w-unsplash.jpg
- marco-peter-Aoah4iWOKm0-unsplash.jpg
- martin-adams-J2f1PriKFEg-unsplash.jpg
- robert-richarz-WOhTfiB-ECs-unsplash.jpg
- Demo-1.jpg
- demo-portrait.jpg
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;
<!-- unimportant stuff, hidden -->
<div @Sys.PageParts.InfoWrapper()>
@Html.Partial("../shared/DefaultInfoSection.cshtml")
<div @Sys.PageParts.InfoIntro()>
<h2>Run an App Query multiple times on the same page</h2>
<p>
The previous examples showed how to use a <code>Query</code>.
Now we want to run the query twice, which requires a <code>Reset()</code>. <br/>
Note that the parameter <code>SiteId</code> is preset to be <code>[Site:Id]</code>.
</p>
<div class="row">
<div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-dnn-files.png", 200, 200, "float-left", label: "Query Tree") </div>
<div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-configuration.png", 200, 200, "float-left", label: "Query Configuration with Params and Test-Values")</div>
<div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-select-statement.png", 200, 200, "float-left", label: "SQL Query using Params")</div>
</div>
</div>
</div>
@{
// Different query in DNN / Oqtane - eg. "SqlTop10FilesDnn"
var queryName = "SqlTop10Files" + CmsContext.Platform.Name;
// get the query and ask for the "Default" results as a dynamic List
// This case doesn't set parameters, so we're using the defaults (current site)
var query = Kit.Data.GetQuery(queryName);
var currentFiles = AsList(query);
// Get a fresh query, so we can use again with other parameters
query = Kit.Data.GetQuery(queryName, parameters: new {
SiteId = CmsContext.Platform.Name == "Dnn" ? 0 : 1
});
var rootFiles = AsList(query);
}
<h3>Files from the current Portal</h3>
<ul>
@foreach (var file in currentFiles) {
<li>@file.Name</li>
}
</ul>
</div>
</div>
<h3>Files from the root portal</h2>
<ul>
@foreach (var file in rootFiles) {
<li>@file.Name</li>
}
</ul>
@* Footer *@
@Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })
Output
- boris-baldinger-eUFfY6cwjSU-unsplash.jpg
- Demo-1.jpg
- Demo-2.jpg
- Demo-3.jpg
- hugo-fergusson-xtQidmET07w-unsplash.jpg
- marco-peter-Aoah4iWOKm0-unsplash.jpg
- martin-adams-J2f1PriKFEg-unsplash.jpg
- robert-richarz-WOhTfiB-ECs-unsplash.jpg
- Demo-1.jpg
- demo-portrait.jpg
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; <!-- unimportant stuff, hidden --> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2>Run an App Query multiple times on the same page</h2> <p> The previous examples showed how to use a <code>Query</code>. Now we want to run the query twice, which requires a <code>Reset()</code>. <br/> Note that the parameter <code>SiteId</code> is preset to be <code>[Site:Id]</code>. </p> <div class="row"> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-dnn-files.png", 200, 200, "float-left", label: "Query Tree") </div> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-configuration.png", 200, 200, "float-left", label: "Query Configuration with Params and Test-Values")</div> <div class="col-4">@Sys.Fancybox.PreviewWithLightbox(App.Path + "/data/assets/sql-query-select-statement.png", 200, 200, "float-left", label: "SQL Query using Params")</div> </div> </div> </div> @{ // Different query in DNN / Oqtane - eg. "SqlTop10FilesDnn" var queryName = "SqlTop10Files" + CmsContext.Platform.Name; // get the query and ask for the "Default" results as a dynamic List // This case doesn't set parameters, so we're using the defaults (current site) var query = Kit.Data.GetQuery(queryName); var currentFiles = AsList(query); // Get a fresh query, so we can use again with other parameters query = Kit.Data.GetQuery(queryName, parameters: new { SiteId = CmsContext.Platform.Name == "Dnn" ? 0 : 1 }); var rootFiles = AsList(query); } <h3>Files from the current Portal</h3> <ul> @foreach (var file in currentFiles) { <li>@file.Name</li> } </ul> </div> </div> <h3>Files from the root portal</h2> <ul> @foreach (var file in rootFiles) { <li>@file.Name</li> } </ul> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })