我的网页包含指向 word 文档和 pdf 文件的链接。对于每个链接,我想显示文件大小和一个显示文件类型的图标。
我认为最好的方法是使用 CSS?任何人都可以给我一个如何做到这一点的例子吗?
谢谢!
最佳答案
当您创建链接 html 时,您需要根据您链接到的文件类型指定 css 类,例如:
<a class="document" href="http://someurl.com/some/file/worddoc.doc" title="Your file size could go here">Word Doc</a>
<a class="pdf" href="http://someurl.com/some/file/somefile.pdf">PDF File</a>
在你的CSS中:
.document {
padding-left: 24px; /* size of icon + a bit */
background: url('document.png') no-repeat;
background-position: left;
}
假设文件在磁盘上,您可以在后面的代码中添加以下内容以获取文件大小。然后,您需要将其转换为更具可读性的内容,并将其添加到上面示例链接中的“title”属性。
System.IO.FileInfo info = new System.IO.FileInfo("filename");
long fileSizeInBytes = info.Length;
或者类似的东西。以上未经测试。
关于c# - 如何显示pdf和word文档的大小和图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3920527/