gpt4 book ai didi

c# - 如何显示pdf和word文档的大小和图标?

转载 作者:行者123 更新时间:2023-11-27 22:30:20 25 4
gpt4 key购买 nike

我的网页包含指向 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com