关于.net:在asp.net中显示文件类型对应的图标 | 珊瑚贝

Show icons corresponding to the file type in asp.net


我需要显示与文件类型对应的图标。
例如,我确实在字符串中有”sample.doc”,我将其显示在锚标记中作为链接以使其可下载。该链接将具有如下所示的文件名

1
Sample

我需要的是我希望链接显示如下

enter

我需要在网页上显示许多文件类型。我怎样才能做到这一点。一个起点对我继续下去会有好处。


我通常这样做(伪代码)

1
2
3
4
5
6
7
8
9
foreach(var file in files){
 var extension = Path.GetExtension(file)

 
 
   <img src=“/images/@(extension).png” />
   Sample
 
}

  • 在此解决方案中,您必须检查图标文件是否存在
  • @Garath我认为在任何解决方案中,您都必须以一种或另一种方式执行此操作
  • 我只想指出您的代码缺少此检查。


我们可以根据asp.net中的文件扩展名显示文件。我们只需要下载文件图标图像,然后编写一些代码来检查文件扩展名并据此获取文件图标。

以下函数可用于获取文件图标:

1
2
3
4
5
6
private string GetIconForFile(string FileName)
    {
        string extension = Path.GetExtension(FileName);
        extension = extension.Trim(‘.’).ToLower();
        return“~/fileicons/” + extension +“.png”;
    }

这里是完整示例的链接:http://programmerskills.blogspot.in/2016/05/show-file-icons-with-filename-in-aspnet.html


你可以在客户端做任何事情。有帮助链接:

  • http://www.hunlock.com/blogs/Attach_icons_to_anything_with_CSS
  • http://cool-javascripts.com/jquery/add-icons-to-your-links-automatically-using-jquery-css.html
  • http://baldwindavid.github.io/jquery-icon/demo/

来源:https://www.codenong.com/16662049/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9519.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?