第 10 章 crifanLib.cs之File/Folder

目录

10.1. 获得当前保存路径:getSaveFolder
10.2. 二进制(字节)数据存为文件:saveBytesToFile
10.3. (从网络上)下载文件(到本地):downloadFile
10.4. 调用资源管理器打开文件夹并选中文件:openFolderAndSelectFile
10.5. (调用系统默认程序直接)打开文件:openFileDirectly

10.1. 获得当前保存路径:getSaveFolder

调用对应的FolderBrowserDialog控件,得到用户所选的(保存文件的)路径


    public string getSaveFolder(FolderBrowserDialog fbdSave)
    {
        string saveFolderPath = "";
        //string saveFolderPath = System.Environment.CurrentDirectory;
        //fbdSaveFolder.SelectedPath = System.Environment.CurrentDirectory;
        DialogResult saveFolderResult = fbdSave.ShowDialog();
        if (saveFolderResult == System.Windows.Forms.DialogResult.OK)
        {
            saveFolderPath = fbdSave.SelectedPath;
        }
        else if (saveFolderResult == System.Windows.Forms.DialogResult.Cancel)
        {
            saveFolderPath = "";
        }

        return saveFolderPath;
    }

    

例 10.1. getSaveFolder 的使用范例


//private System.Windows.Forms.FolderBrowserDialog fbdSaveFolder;
string saveFolderPath = getSaveFolder(fbdSaveFolder);