I wonder how could I improve these code that it will automatically recognize file in the folder "/Doc/Projekti/<%=dat%>" and chose the right icon from "/Img/image.png". In this folder, I have icons for pdf, xls, word,... All these icons are in png format. Here is my code I currently using but on all files that code find is now pdf icon
<%
string adresa = (string)Application["naslov"];
string adresa1 = adresa + "doc\\Projekti";
var t=2;
DirectoryInfo info = new DirectoryInfo(adresa1);
FileInfo[] files = info.GetFiles().OrderByDescending(p => p.CreationTime).ToArray();
foreach (FileInfo dat in files){
var test=dat;
if(test.ToString() != "Thumbs.db"){
%>
<a href="/Doc/Projekti/<%=dat%>" style="color:#6c8230; padding: 0 0 10px 10px; text-decoration: none;" target="_blank"><img src="/Img/pdf.png" style="border: 0px" alt="PDF"><%=dat%></a><BR>
答案 0 :(得分:0)
在分配图标时,调用一个函数,该函数获取文件名作为输入,并根据文件扩展名返回匹配的png图标。