How To Create File Selection Dialog Box in PowerShell

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ม.ค. 2025

ความคิดเห็น • 3

  • @echy
    @echy ปีที่แล้ว

    why can folder name not show up in the file textbox

  • @Rasinzz
    @Rasinzz ปีที่แล้ว +1

    Is there anyway I can use this to select a folder rather than a file?

    • @SwapnilInfotech
      @SwapnilInfotech  ปีที่แล้ว

      Yes You can achieve that by using the below script which will open the Folder selection dialog box. But it will be different from the File selection dialog box. Please let me know if you have any questions. $out variable will have folder path in it.
      ===============================
      $FolderBrowser = new-object System.Windows.Forms.folderbrowserdialog;
      $out = $null;
      $caller = [System.Windows.Forms.NativeWindow]::new()
      $caller.AssignHandle([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
      if (($FolderBrowser.ShowDialog($caller)) -eq [System.Windows.Forms.DialogResult]::OK.value__)
      {
      $out = $FolderBrowser.SelectedPath;
      }
      $out
      ===============================