FileDialogs

Function SaveFileDialog{
    Param(
        [Parameter(Mandatory=$True)]
        $Filetype
    )
    [Void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
    $SaveFileDialog.Filter = "$Filetype files (*.$Filetype)|*.$Filetype|All files (*.*)|*.*"
    $status = $SaveFileDialog.ShowDialog()

    If($status -eq "Cancel"){$Return = $status}
    Else{$Return = $SaveFileDialog.FileName}

    $SaveFileDialog.Dispose()
    Return $Return
}
Function SelectFileDialog{
    Param(
        [Parameter(Mandatory=$True)]
        $Filetype
    )
    [Void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog

    $OpenFileDialog.Filter = "$Filetype files (*.$Filetype)|*.$Filetype|All files (*.*)|*.*"

    $status = $OpenFileDialog.ShowDialog()

    If($status -eq "Cancel"){$Return = $status}
    Else{$Return = $OpenFileDialog.FileName}

    $OpenFileDialog.Dispose()
    Return $Return
}
Function SelectFolderDialog{
    [Void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    $SelectFileDialog = New-Object System.Windows.Forms.FolderBrowserDialog
    $status = $SelectFileDialog.ShowDialog()

    If($status -eq "Cancel"){$Return = $status}
    Else{$Return = $SelectFileDialog.FileName}

    $SelectFileDialog.Dispose()
    Return $Return
}

Leave a Reply