产品使用及交流论坛

首页 » 产品使用交流区 » 安装及使用交流 » 怎么获取附件的大小及扩展名。
bluexq - 2013/7/23 15:55:20
新建了一个产品帮助手册模型 ,怎么获取附件的大小及扩展名。 因为需要在前台显示附件大小及扩展名。
xiyou - 2013/7/24 10:43:15
  1. <script runat="server" language="c#">
  2. private string filesize(string files) //获取文件大小
  3.     {
  4.         strin Rn = "";
  5.         if (!string.IsNullOrEmpty(files))
  6.         {
  7.             if (System.IO.File.Exists(Server.MapPath(files)))
  8.             {
  9.                  System.IO.FileInfo FI = new System.IO.FileInfo(Server.MapPath(files));
  10. Rn= FI.Length.ToString() ;
  11.             }
  12.         }
  13.         return Rn;
  14.     }

  15. private string fileext(string files) //获取文件扩展名
  16.     {
  17.         strin Rn = "";
  18.         if (!string.IsNullOrEmpty(files))
  19.         {
  20.             if (System.IO.File.Exists(Server.MapPath(files)))
  21.             {
  22.                   System.IO.FileInfo FI = new System.IO.FileInfo(Server.MapPath(files));
  23.   Rn= FI.Extension;
  24.             }
  25.         }
  26.         return Rn;
  27.     }
  28. </script>
复制代码
把这个方法放在模型顶部,模型中直接调用.
bluexq - 2013/7/24 13:02:30
放在模型顶部,出错呀!

Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The value of the property 'mode' cannot be parsed. The error is: The enumeration value must be one of the following: RemoteOnly, On, Off.

Source Error:


Line 16:     <compilation defaultLanguage="C#" debug="false" />
Line 17:     <authentication mode="Forms" />
Line 18:     <customErrors mode="on">
Line 19:       <error statusCode="404" redirect="/err404.htm" />
Line 20:     </customErrors>

Source File: D:\wwwroot\web.config    Line: 18
bluexq - 2013/7/25 19:06:34
程序出错呀。!  有人能解答一下吗?
bluexq - 2013/7/27 18:08:49
[code]<script runat="server" language="c#">
private string filesize(string files) //获取文件大小
    {
        strin Rn = "";
        if (!string.IsNullOrEmpty(......
xiyou 发表于 2013-7-24 10:43:15
终于搞定了,原来是是声明字符串变量少个字母 g,
1
查看完整版本: 怎么获取附件的大小及扩展名。