zoukankan      html  css  js  c++  java
  • OpenFileDialog SaveFileDialog

    public TestOne()
    {
     InitializeComponent();
     SaveFileDialog();//调用打开SaveFileDialog 保存对话框
    }
    
    #region 保存对话框
    private void SaveFileDialog()
    {
     //string localFilePath, fileNameExt, newFileName, FilePath;
     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
    
     //设置文件类型
     saveFileDialog1.Filter = " txt files(*.txt)|*.txt|All files(*.*)|*.*";
    
     //设置默认文件类型显示顺序
     saveFileDialog1.FilterIndex = 2;
    
     //保存对话框是否记忆上次打开的目录
     saveFileDialog1.RestoreDirectory = true;
    
     //点了保存按钮进入
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
      //获得文件完整名
      //localFilePath = saveFileDialog1.FileName.ToString();
    
      //获取文件名,不带路径
      //fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
    
      //获取文件路径,不带文件名
      //FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
    
      //给文件名前加上时间
      //newFileName = DateTime.Now.ToString("yyyyMMdd") + fileNameExt;
    
      //在文件名里加字符
      //saveFileDialog1.FileName.Insert(1,"dameng");
        
      System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();//输出文件
    
                          //fs输出带文字或图片的文件,就看需求了
     }
    }
    
    #endregion
    

    获取OpenFileDialog的文件名和文件路径

    System.IO.Path.GetFileName(openFileDialog1.FileName);//得到文件名

    System.IO.Path.GetDirectoryName(openFileDialog1.FileName);//得到路径

  • 相关阅读:
    采样错误
    MathJax
    jupyter
    pip
    str操作
    Content-Type
    json转csv
    【tornado】静态文件
    dict 字典
    基于插件技术的GIS应用框架(C# + ArcEngine9.3)(一)
  • 原文地址:https://www.cnblogs.com/hl3292/p/1895598.html
Copyright © 2011-2022 走看看