Rahul Sharma
Rahul Sharma

Reputation: 190

I would like to open an file in powershell using the search from windows

I would like to open an file in powershell using the search from windows.

The problem is as followed I have an script that is:

1.reading out an .txt file
2.logs into an database
3. ads multiple rows in the tabel

This works like it should. Now comes the problem that the .txt file is found with an url that is hardcoded in the script:

$textfile= Get-Content C:\ODP.NET\test.txt

What I would like to do is that the user can open his own file using a simple search engine from windows. Take a look at the link below.

the link

good luck!

Upvotes: 0

Views: 115

Answers (1)

Rahul Sharma
Rahul Sharma

Reputation: 190

The answer

Function Get-FileName($initialDirectory)
{   
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
 Out-Null

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "All files (*.*)| *.*"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
} #end function Get-FileName

Get-FileName -initialDirectory "c:\fso"

Upvotes: 2

Related Questions