简体   繁体   English

如何显示PDF和Word文档的大小和图标?

[英]How to display size and icon for pdf and word docs?

I have webpages that contain links to word documents and pdf files. 我有一些网页,其中包含指向Word文档和pdf文件的链接。 For each link I want to display the file size and an icon showing what the file type is. 对于每个链接,我要显示文件大小和一个图标,显示文件类型。

I'm thinking the best way to do this would be with CSS? 我想最好的方法是使用CSS? Can anybody give me an example of how to do this? 有人可以给我举一个例子吗?

Thanks! 谢谢!

When you create the link html you will need to specify the css class based on the file type you are linking to eg: 创建链接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>

In your css: 在您的CSS中:

.document {
  padding-left: 24px; /* size of icon +  a bit */
  background: url('document.png') no-repeat;
  background-position: left;
}

In your code behind you can add the following to get the file size, assuming the file is on disk. 假设文件在磁盘上,则可以在后面的代码中添加以下内容来获取文件大小。 You would then need to convert this to something more readable and add it to the "title" attribute in the example links above. 然后,您需要将其转换为更易读的内容,并将其添加到以上示例链接中的“ title”属性中。

System.IO.FileInfo info = new System.IO.FileInfo("filename");
long fileSizeInBytes = info.Length;

Or something along those lines. 或类似的规定。 Above is not tested. 以上未经测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM