Fork me on GitHub
DNN Apps - Demo-Zone
Discover DNN-Apps - simple and elegant, easy to customize
You are here: Home  >  Apps  >  File List of a folder

Files in some folder

Files in /App-Demos/Content/Apps/Data/
  1. Beni.jpg (166 kB)
  2. Daniel.jpg (216 kB)
  3. Raphael.jpg (314 kB)

Look inside

Content Item

These are the values a content-editor can manage.
Name Type Value
Title System.String Files in some folder
Folder System.String /App-Demos/Content/Apps/Data/

Presentation Item

These are additional, optional presentation instructions a content-editor can manage. If none are entered, a default set (predefined by the designer) will be used.

No Presentation parameters specified, using default presentation for this item.

Template file

<h1>@Content.Title @Content.Toolbar</h1>
	// Must first get the correct folder
	string folder = Content.Folder;

	// just in case it was a file (so the folder has like image.jpg or something), truncate that
	// this would happen if the user didn't type in a folder, but actually picked a file
	folder = folder.Replace('\\', '/');
	if (folder.LastIndexOf('.') > folder.LastIndexOf('/'))
		folder = folder.Substring(0, folder.LastIndexOf('/'));
	if (folder[folder.Length - 1] != '/')
		folder = folder + '/';
	// get the folder
	var directoryPath = Server.MapPath(folder);
	var directoryInfo = new DirectoryInfo(directoryPath);
	if (!directoryInfo.Exists)
		<div>Folder not found</div>

	var files = directoryInfo.GetFiles();
	if (!files.Any())
		<p>no files found in folder</p>
	<div>Files in @folder</div>

		@foreach (var file in files)
		<li><a href="@(folder + file.Name)" target="_blank">@file</a> (@(file.Length / 1024) kB)</li>

2serve . 2invent . 2create is 2be.