SOLUTION on the bottom .
I find my self how to use
($openfiledialog1.ShowDialog() -eq 'OK')
{
$textboxFile.Text = $openfiledialog1.FileName
}
I can extract and change the text inside of this file and save at the same path.
I would like to save in another place and I tried some thing
(Get-Content $textboxFile.Text).Replace('$Name', 'test') |
Out-File $HOME\$openfiledialog1.SafeFileNames
I tried with Set-Content
same issue, the script can't save and error appear.
ERROR: Set-Content : Could not open the alternate data stream ' Title: , FileName: C:\Users\Administrator.SERVERAD\Documents\test.txt' of the file ERROR: 'C:\Users\Administrator.SERVERADSystem.Windows.Forms.OpenFileDialog'. MainForm.psf (24, 59): ERROR: At Line: 24 char: 59 ERROR: + ... xt).replace('$Name', 'test')|Set-Content -Path $HOME\$openfiledialog1
The final usage is change some data inside of HTML file.
Ansgar I don't understand your solution but you keep me on the good way thank you so much.
After 2 hours and some break I find a SOLUTION, but I don't why I can't use directly $openfiledialog1.SafeFileName
.
$buttonBrowse_Click = {
if ($openfiledialog1.ShowDialog() -eq 'OK') {
$textboxFile.Text = $openfiledialog1.SafeFileName
}
}
$button1_Click = {
$b = $textboxFile.Text
# also this things work too $b=$openfiledialog1.SafeFileName
# TODO: Place custom script here
(Get-Content $openfiledialog1.FileName).replace('$Name', "text") |
Out-File $HOME\$b
}