Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
how does one get a no-extension file via "System.Windows.Forms.OpenFileDialog"?
Post Body

howdy y'all,

i needed to make a file picker for a friend and got it working using the System.Windows.Forms.OpenFileDialog stuff. nice and easy.

except for one thing ... it won't allow picking a no-extension file. [sigh ...]

hopefully some kind person will enlighten me on this. [grin] here's my code ...

Function Show-SelectFileDialog
    {
    [CmdletBinding()]

    Param
        (
        [Parameter (
            Mandatory,
            Position = 0
            )]
            [ValidateNotNullOrEmpty()]
            [string]
            $TopDir,

        # extension examples = "*", "*.*", "log", ".txt", "*.csv"
        [Parameter (
            Position = 1
            )]
            [string]
            $FileType = '*.*'
        )

    switch ($FileType)
        {
        {$_ -in ('.', '*.')}
            {
            $FilterString = "Extensionless files (*.)|*.|All files (*.*)|*.*"
            break
            }
        {$_ -in ('', '*', '.*', '*.*')}
            {
            $FilterString = "All files (*.*)|*.*"
            break
            }
        {$_.StartsWith('*.')}
            {
            $TypeName = $_.TrimStart('*.').ToUpper()
            $FilterString = "$TypeName files ($FileType)|$FileType|All files (*.*)|*.*"
            break
            }
        {$_.StartsWith('.')}
            {
            $TypeName = $_.TrimStart('.').ToUpper()
            $FilterString = "$TypeName files (*$FileType)|*$FileType|All files (*.*)|*.*"
            break
            }
        default
            {
            $TypeName = $_.ToUpper()
            $FilterString = "$TypeName files (*.$FileType)|*.$FileType|All files (*.*)|*.*"
            }
        }

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") |
        Out-Null
    $SelectFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $SelectFileDialog.InitialDirectory = $TopDir
    $SelectFileDialog.Filter = $FilterString
    $SelectFileDialog.Title = 'Please select a file and then click [OK]'
    $SelectFileDialog.ShowDialog() |
        Out-Null
    $SelectFileDialog.FileName
    }

take care,
lee

Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
27,226
Link Karma
672
Comment Karma
25,727
Profile updated: 3 days ago
Posts updated: 8 months ago
[grin]

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
7 years ago