I have a directory with release note files, I need to show a link to their pdf in website:
File names look like this:
Appower Release Notes 2.104.0_August102021.pdf
Appower Release Notes 2.107.0_November092021.pdf
Appower Release Notes 2.108.0_December072021.pdf
HTML markup:
<ol>
<li>
<a download="" href="~/Content/ReleaseNotes/ Appower Release Notes 2.104.0_August102021.pdf">August</a>
</li>
<li>
<a download="" href="~/Content/ReleaseNotes/Appower Release Notes 2.107.0_November092021.pdf">November</a>
</li>
<li>
<a download="" href="~/Content/ReleaseNotes/Appower Release Notes 2.108.0_December072021.pdf">December</a>
</li>
</ol>
Instead of hardcoding August, November and December, I need to get the month from File name, so Every time that I upload files I can get the name dynamically instead of code change,
I have tried to use this code:
var enumDir = Directory.GetFiles(Server.MapPath("~/Content/ReleaseNotes"))
.Where(a => Path.GetFileName(a).Length > 12);
foreach (var item in enumDir)
{
var alt_right6 = new string(item.Reverse().Take(10).Reverse().ToArray());
}
This code will return this: 102021.pdf - how get December from this?
Also open to better approach.
string month = new System.Text.RegularExpressions.Regex("([^A-Z]*)([a-zA-Z]*)").Match(Path.GetFileNameWithoutExtension(item).Split('.').Last()).Groups[2].Value;