Posted on 02/01/2017 13:29:03
Hi Hans,
I am sorry for this late reply.
Here are a few examples:
1. Assuming you want a specific path and also want to use the metadata on the file:
@{
List<Dictionary<string, string>> documentsList = GetDocumentFiles("/Files/Documents/" + productId + "/");
foreach (System.Collections.Generic.Dictionary<String, String> fileStr in documentsList)
{
string file = fileStr["file"];
var metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(file);
string temp = @".",
metafield = "title",
fileName = file.Substring((file.LastIndexOf("/") + 1), (file.Length - file.LastIndexOf("/") - 1)),
fileTitle = metadata != null && metadata.GetValue(metafield).ToString() != "" ? metadata.GetValue(metafield).ToString() : fileName,
substringFile = file.Substring((file.LastIndexOf(temp) + 1), (file.Length - file.LastIndexOf(temp) - 1)),
<li>
<a class="downloadFile" href="@file"><i class='fa fa-file'></i> @fileTitle</a>
</li>
}
}
2. If you want to use the convention in the details loop:
@if (GetLoop("Details").Any())
{
@*Shared files*@
foreach (LoopItem detail in GetLoop("Details").Where(x => x.GetString("Ecom:Product:Detail.Image.Clean").StartsWith("your_path/NamingConvention/")))
{
string file = detail.GetString("Ecom:Product:Detail.Image.Clean");
var metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(file);
string temp = @".",
metafield = "title",
fileTitle = metadata != null ? metadata.GetValue(metafield).ToString() : Translate("download", "Download"),
substringFile = file.Substring((file.LastIndexOf(temp) + 1), (file.Length - file.LastIndexOf(temp) - 1)),
<li>
<a class="downloadFile" href="@file"><i class='fa fa-file'></i> @fileTitle</a>
</li>
}
}
The code might be rough on the edges but I am confident it can help you go in the right direction.
Adrian