I'm trying to make a table that lists 2 types of files linked together. One type are .mp3, and the other are .txt files. I want these files to be linked together, such that the files that share the same name share one row, when the foreach loop passes through them. This is so that the mp3 files can be played, and the corresponding text file can be opened.
App.razor page has a table that displays all files in a folder, but it doesn't take into account if the files of the 2 types share the same name. Can anybody help with how to make a class that has the files linked together so that they can be called in the table?
Here is the code.
<table class="table table-striped mb-0">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
@foreach (var file in textList)
{
<tr>
<td>
@file.Name
</td>
<td>
<span @onclick="() => PlayAudio(file.Url)"
class="text-primary oi oi-play-circle me-2" aria-hidden="true" role="button">
</span>
<span @onclick="() => DeleteAudio(file)"
class="text-danger oi oi-trash" aria-hidden="true" role="button">
</span>
<span @onclick="() => openTextFile(file)"
><button>Open</button>
</span>
</td>
</tr>
}
}
</tbody>
</table>
@code{
readonly List<TextFile> textList = new();
readonly string FolderName = "textSoundFiles";
protected override void OnInitialized()
{
var path = $"{env.WebRootPath}\\{FolderName}\\";
var files = new DirectoryInfo(path).GetFiles();
foreach (var file in files)
{
textList.Add(new TextFile
{
Name = file.Name,
Url = $"/textFiles/{file.Name}",
Path = file.FullName
});
}
}
public class TextFile
{
public string Name { get; set; }
public string Url { get; set; }
public string Path { get; set; }
}
}
I'm trying to make a table that lists files, that allows me to play audio from the audio files that are listed. I'm trying to 2 type of files within a directory, such that the files that have the same names(excluding their MIME type) are linked to each other