This example queries the DNN SQL for the files using a DataTable
object.
⬇️ Result | Source ➡️
- image-1.jpg
- image-2.jpg
- ct basic content.png
- ct image.png
- ct layout element.png
- ct links.png
- ct location.png
- ct person.png
- ct video.png
- RazorTutoApp1000x1000.png
@inherits Custom.Hybrid.RazorTyped
@using ToSic.Razor.Blade
@using System.Linq
@using System.Configuration
@using System.Data
@using System.Data.SqlClient
@{
// load the sql connection name from Web.Config
// the default connection string for DNN is SiteSqlServer
var conString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ToString();
// You should always write parameters using the @-syntaxt,
// and never write them directly into the SQL using string-concatenation
// to protect yourself from SQL injection attacks
const string sqlCommand = "Select Top 10 * from Files Where PortalId = @PortalId";
// create an adapter object, tell it what to do, and load results into fileTable
var adapter = new SqlDataAdapter(sqlCommand, conString);
adapter.SelectCommand.Parameters.AddWithValue("@PortalId", MyContext.Site.Id);
var fileTable = new DataTable();
adapter.Fill(fileTable);
}
<ol>
@foreach (DataRow row in fileTable.Rows)
{
<li>@row["FileName"]</li>
}
</ol>