zoukankan      html  css  js  c++  java
  • 选择文件选择文件夹

    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;
    }}

  • 相关阅读:
    java-HTML&javaSkcript&CSS&jQuery&ajax
    HTML&javaSkcript&CSS&jQuery&ajax-XSS
    XSS-HTML&javaSkcript&CSS&jQuery&ajax-CSS
    XSS-HTML&javaSkcript&CSS&jQuery&ajax
    HTML&javaSkcript&CSS&jQuery&ajax-Css
    论坛IP地址追踪&路由器密码嗅探
    java ArrayList
    WireShark Flow capture analysis
    Software tips
    301. Remove Invalid Parentheses
  • 原文地址:https://www.cnblogs.com/ilison/p/10812465.html
Copyright © 2011-2022 走看看