zoukankan      html  css  js  c++  java
  • System.IO.Path 文件名、路径、扩展名处理

    string filePath =@"E:/Randy0528/中文目录/JustTest.rar";

    更改路径字符串的扩展名。
    System.IO.Path.ChangeExtension(filePath, "txt");
    E:/Randy0528/中文目录/JustTest.txt

    返回指定路径字符串的目录信息。
    System.IO.Path.GetDirectoryName(filePath);
    E:/Randy0528/中文目录

    返回指定的路径字符串的扩展名。
    System.IO.Path.GetExtension(filePath);
    .rar

    返回指定路径字符串的文件名和扩展名。
    System.IO.Path.GetFileName(filePath);
    JustTest.rar

    返回不具有扩展名的指定路径字符串的文件名。
    System.IO.Path.GetFileNameWithoutExtension(filePath);
    JustTest

    获取指定路径的根目录信息。
    System.IO.Path.GetPathRoot(filePath);
    E:/

    返回随机文件夹名或文件名。
    System.IO.Path.GetRandomFileName();
    ct2h5b2h.sed

    创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。
    System.IO.Path.GetTempFileName();
    C:/Documents and Settings/Randy/Local Settings/Temp/tmpAD.tmp

    返回当前系统的临时文件夹的路径。
    System.IO.Path.GetTempPath();
    C:/Documents and Settings/Randy/Local Settings/Temp/

    确定路径是否包括文件扩展名。
    System.IO.Path.HasExtension(filePath);
    True

    获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
    System.IO.Path.IsPathRooted(filePath);
    True

    后台获取上传文件

    HttpPostedFileBase fileData=Request.Files[0];

    string FileName =System.IO.Path.GetFileNameWithoutExtension(fileData.FileName);

    #region 对文件名称进行格式处理
    public string CheckFileName(string FileName) {
      //对文件名称进行格式处理
      FileName=FileName.Replace('&', ' ');
      FileName = FileName.Replace('#', ' ');
      FileName = FileName.Replace('%', ' ');
      FileName = FileName.Replace('_', ' ');
      FileName = FileName.Replace('+', ' ');
      FileName = FileName.Trim();
      if (FileName.Length > 22)
      {
        FileName = FileName.Substring(0, 22);
      }
      else if (FileName.Length == 0)
      {
        FileName = "附件";
      }
      return FileName;
    }

    参考:http://blog.csdn.net/chanyinhelv/article/details/8432840

  • 相关阅读:
    Android中Handler原理
    微软柯塔娜(Cortana)的一句名言
    C# 单例模式的五种写法
    HTTP Status 404
    PLSQL中显示Cursor、隐示Cursor、动态Ref Cursor差别
    Android 开发之集成百度地图的定位与地图展示
    iOS知识点汇总
    优化报表系统结构之报表server计算
    淘宝中间的一像素线(手机端)
    解决yum升级的问题“There was a problem importing one of the Python modules”
  • 原文地址:https://www.cnblogs.com/fengduandeai/p/8575494.html
Copyright © 2011-2022 走看看