zoukankan      html  css  js  c++  java
  • c#几个常用的代码

    1、获取“我的文档”等一些系统文件夹路径
    Environment.SpecialFolder中包含了一些系统文件夹信息
    MessageBox.Show(Environment.GetFolderPath( Environment.SpecialFolder.Personal ));

    2、获取 硬盘临时文件夹
    this.p_runFilePath=System.Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)+@"\Content.IE5\aaa";

    3、获取应用程序当前执行的路径
    string appPath = Application.ExecutablePath;

    4、 如何确定当前运行的系统
    OperatingSystem os = Environment.OSVersion;
    MessageBox.Show(os.Version.ToString());
    MessageBox.Show(os.Platform.ToString());

    5、从完整的路径中获取文件名
    用System.IO.Path.GetFileName 和 System.IO.Path.GetFileNameWithoutExtension(无扩展名)的方法

    6、从完整的路径中获取文件扩展名
    用System.IO.Path.GetExtension方法

    7、被执行的EXE文件所在的目录。

    如果是WinForm,可以使用System.Windows.Forms.Application类提供的StartupPath属性。

    此外,AppDomain.CurrentDomain.BaseDirectory 属性也可以获得EXE文件所在的目录。

    Directory.GetCurrentDirectory(); 获取应用程序的当前工作目录,
    应该是应用程序最后一次操作过的目录。(比如在操作 OpenFileDialog 后就会改变。)
    最后一位[ 不 ]包括"\"

    AppDomain.CurrentDomain.BaseDirectory; 程序集的基目录,
    最后一位包括"\"

    string savingPath = AppDomain.CurrentDomain.BaseDirectory;
    if(!savingPath.EndsWith(@"\"))
    {
    savingPath += @"\";
    }
    savingPath += "TL_"+DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

    if(!Directory.Exists(savingPath))
    {
    Directory.CreateDirectory(savingPath);
    }

  • 相关阅读:
    Gridview使用CheckBox全选与单选 Version 2
    Repeater控件第前10笔记录高亮显示
    下拉式菜单(DropDownList)连动的选择
    DataList控件显示图片要的是效果
    电容屏、电阻屏基础知识
    SIM300实现GPRS上网
    qt练习7 定时爆炸小游戏
    用 STL vector 来创建二维数组
    sim300_at命令.doc
    QT练习6 label,button创建,点击按键关闭
  • 原文地址:https://www.cnblogs.com/flashicp/p/693986.html
Copyright © 2011-2022 走看看