• 选择文件选择文件夹


    namespace Microsoft.Win32

    选择文件:

    if (string.IsNullOrEmpty(folderInitialDirectory))
    {
    folderInitialDirectory = FileAndFolderOperation.Instance.GetUserDocumentFolder();
    }

    SaveFileDialog saveFileDialog = new SaveFileDialog();


    saveFileDialog.Title = Resources.ChooseExportFilePathWndTitle;
    saveFileDialog.InitialDirectory = folderInitialDirectory;
    saveFileDialog.Filter = Resources.ChooseExportFilePathWndFilter;
    saveFileDialog.FilterIndex = 1;
    saveFileDialog.RestoreDirectory = true;
    if (saveFileDialog.ShowDialog() == true)
    {

    FilesPath = saveFileDialog.FileName;
    folderInitialDirectory = System.IO.Path.GetDirectoryName(FilesPath);
    }

    选择文件夹:

    Microsoft.WindowsAPICodePack.Dialogs

    CommonOpenFileDialog dialog = new CommonOpenFileDialog();
    dialog.IsFolderPicker = true;  // 这里一定要设置true,不然就是选择文件
    if (string.IsNullOrEmpty(folderInitialDirectory))
    {
    folderInitialDirectory = FileAndFolderOperation.Instance.GetUserDocumentFolder();
    }
    dialog.InitialDirectory = folderInitialDirectory;
    if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
    {
    ToFolderPath = dialog.FileName;
    ImportExtentions.Instance.SetImpToFolderName(ToFolderPath);
    folderInitialDirectory =ToFolderPath;
    var zippath = ImportExtentions.Instance.ImpFromFolderName;
    var strZipPath = System.IO.Path.GetDirectoryName(zippath);
    string strRoot = System.IO.Path.GetPathRoot(strZipPath);
    var zipFreeSpace = FileAndFolderOperation.Instance.GetHardDiskFreeSpace(strRoot);

    string strRoot1 = "";
    var strPath = System.IO.Path.GetDirectoryName(ToFolderPath);
    if(!string.IsNullOrWhiteSpace(strPath))
    strRoot1 = System.IO.Path.GetPathRoot(strPath);
    else
    strRoot1 = System.IO.Path.GetPathRoot(ToFolderPath);

    var lfreeSpace = FileAndFolderOperation.Instance.GetHardDiskFreeSpace(strRoot1);

    if (zipFreeSpace > lfreeSpace)
    {
    SetSizeErrorInfo();
    return;
    }}

  • 相关阅读:
    linux fork, system, exec()
    wiegand 问题
    route/ip route的作用
    The Name/Origin of Country names
    修改 timezone
    Socket 广播
    IC卡的逻辑卡号和市民卡卡号
    32位和64位程序
    短连接和长连接
    各个公司的来源/The etymology of company
  • 原文地址:https://www.cnblogs.com/ilison/p/10812465.html
Copyright © 2020-2023  润新知