Link to home
Create AccountLog in
Avatar of Mandy_
Mandy_

asked on

Powershell Primal forms - add filedialog and write result in textbox

Hi,

how could i create a filedialog at this points i marked in the script. Now i just have the
path in a textbox. In this version of primal forms its not possible to create filedialog
line 38, 44 ....
Pls see this code. it's really difficult for me to integrate and i want to see the result
of the openfiledialog in the textbox i mean the path and filename
 $DialogResult = $openFileDialog1.ShowDialog()
   If ($openFileDialog1.Filename.Length -gt 0 ) {
        Write-Host $openFileDialog1.Filename
        [System.Windows.Forms.MessageBox]::Show($openFileDialog1.Filename)

Open in new window




#Generated Form Function
function GenerateForm {

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$label9 = New-Object System.Windows.Forms.Label
$label8 = New-Object System.Windows.Forms.Label
$label7 = New-Object System.Windows.Forms.Label
$label6 = New-Object System.Windows.Forms.Label
$label5 = New-Object System.Windows.Forms.Label
$button4 = New-Object System.Windows.Forms.Button
$textBox5 = New-Object System.Windows.Forms.TextBox
$button3 = New-Object System.Windows.Forms.Button
$textBox4 = New-Object System.Windows.Forms.TextBox
$label4 = New-Object System.Windows.Forms.Label
$button2 = New-Object System.Windows.Forms.Button
$textBox3 = New-Object System.Windows.Forms.TextBox
$label2 = New-Object System.Windows.Forms.Label
$textBox2 = New-Object System.Windows.Forms.TextBox
$label3 = New-Object System.Windows.Forms.Label
$label1 = New-Object System.Windows.Forms.Label
$button1 = New-Object System.Windows.Forms.Button
$textBox1 = New-Object System.Windows.Forms.TextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$enable_pw= 
{
#FileDialog at this step

}

$createsmtp= 
{
#FileDialog at this step

}

$convert_csv= 
{
#FileDialog at this step

}

$writebacktocsv= 
{
#FileDialog at this step

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$form1.BackColor = [System.Drawing.Color]::FromArgb(255,212,208,200)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 546
$System_Drawing_Size.Width = 426
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$form1.Name = "form1"
$form1.Text = "Test"

$label9.DataBindings.DefaultDataSourceUpdateMode = 0
$label9.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 104
$System_Drawing_Point.Y = 439
$label9.Location = $System_Drawing_Point
$label9.Name = "label9"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 16
$System_Drawing_Size.Width = 175
$label9.Size = $System_Drawing_Size
$label9.TabIndex = 18
$label9.Text = "Output path and filename"
$label9.TextAlign = 16

$form1.Controls.Add($label9)

$label8.DataBindings.DefaultDataSourceUpdateMode = 0
$label8.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 115
$System_Drawing_Point.Y = 341
$label8.Location = $System_Drawing_Point
$label8.Name = "label8"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 14
$System_Drawing_Size.Width = 164
$label8.Size = $System_Drawing_Size
$label8.TabIndex = 17
$label8.Text = "Input path and filename"

$form1.Controls.Add($label8)

$label7.DataBindings.DefaultDataSourceUpdateMode = 0
$label7.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 115
$System_Drawing_Point.Y = 226
$label7.Location = $System_Drawing_Point
$label7.Name = "label7"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 19
$System_Drawing_Size.Width = 164
$label7.Size = $System_Drawing_Size
$label7.TabIndex = 16
$label7.Text = "Input path and filename"
$label7.TextAlign = 16

$form1.Controls.Add($label7)

$label6.DataBindings.DefaultDataSourceUpdateMode = 0
$label6.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,5,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 54
$System_Drawing_Point.Y = 409
$label6.Location = $System_Drawing_Point
$label6.Name = "label6"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 19
$System_Drawing_Size.Width = 380
$label6.Size = $System_Drawing_Size
$label6.TabIndex = 15
$label6.Text = "4.Add SMTP column and convert back"

$form1.Controls.Add($label6)

$label5.DataBindings.DefaultDataSourceUpdateMode = 0
$label5.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,5,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 54
$System_Drawing_Point.Y = 318
$label5.Location = $System_Drawing_Point
$label5.Name = "label5"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 339
$label5.Size = $System_Drawing_Size
$label5.TabIndex = 14
$label5.Text = "3.Create SMTP"

$form1.Controls.Add($label5)


$button4.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 307
$System_Drawing_Point.Y = 456
$button4.Location = $System_Drawing_Point
$button4.Name = "button4"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 67
$button4.Size = $System_Drawing_Size
$button4.TabIndex = 13
$button4.Text = "Go"
$button4.UseVisualStyleBackColor = $True
$button4.add_Click($writebacktocsv)

$form1.Controls.Add($button4)

$textBox5.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 90
$System_Drawing_Point.Y = 458
$textBox5.Location = $System_Drawing_Point
$textBox5.Name = "textBox5"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 22
$System_Drawing_Size.Width = 201
$textBox5.Size = $System_Drawing_Size
$textBox5.TabIndex = 12
$textBox5.Text = "c:\import.csv"

$form1.Controls.Add($textBox5)


$button3.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 307
$System_Drawing_Point.Y = 356
$button3.Location = $System_Drawing_Point
$button3.Name = "button3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 67
$button3.Size = $System_Drawing_Size
$button3.TabIndex = 11
$button3.Text = "Go"
$button3.UseVisualStyleBackColor = $True
$button3.add_Click($createsmtp)

$form1.Controls.Add($button3)

$textBox4.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 92
$System_Drawing_Point.Y = 358
$textBox4.Location = $System_Drawing_Point
$textBox4.Name = "textBox4"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 22
$System_Drawing_Size.Width = 200
$textBox4.Size = $System_Drawing_Size
$textBox4.TabIndex = 10
$textBox4.Text = "c:\export.csv"

$form1.Controls.Add($textBox4)

$label4.DataBindings.DefaultDataSourceUpdateMode = 0
$label4.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,5,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 83
$System_Drawing_Point.Y = 203
$label4.Location = $System_Drawing_Point
$label4.Name = "label4"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 234
$label4.Size = $System_Drawing_Size
$label4.TabIndex = 9
$label4.Text = "2.Enable Mailbox and PW-Reset "

$form1.Controls.Add($label4)


$button2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 307
$System_Drawing_Point.Y = 248
$button2.Location = $System_Drawing_Point
$button2.Name = "button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 67
$button2.Size = $System_Drawing_Size
$button2.TabIndex = 8
$button2.Text = "Go"
$button2.UseVisualStyleBackColor = $True
$button2.add_Click($enable_pw)

$form1.Controls.Add($button2)

$textBox3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 90
$System_Drawing_Point.Y = 248
$textBox3.Location = $System_Drawing_Point
$textBox3.Name = "textBox3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 22
$System_Drawing_Size.Width = 202
$textBox3.Size = $System_Drawing_Size
$textBox3.TabIndex = 7
$textBox3.Text = "c:\export.csv"

$form1.Controls.Add($textBox3)

$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 104
$System_Drawing_Point.Y = 109
$label2.Location = $System_Drawing_Point
$label2.Name = "label2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 25
$System_Drawing_Size.Width = 201
$label2.Size = $System_Drawing_Size
$label2.TabIndex = 6
$label2.Text = "Output path and filename"
$label2.TextAlign = 16

$form1.Controls.Add($label2)

$textBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 90
$System_Drawing_Point.Y = 137
$textBox2.Location = $System_Drawing_Point
$textBox2.Name = "textBox2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 22
$System_Drawing_Size.Width = 202
$textBox2.Size = $System_Drawing_Size
$textBox2.TabIndex = 5
$textBox2.Text = "c:\export.csv"

$form1.Controls.Add($textBox2)

$label3.DataBindings.DefaultDataSourceUpdateMode = 0
$label3.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 115
$System_Drawing_Point.Y = 51
$label3.Location = $System_Drawing_Point
$label3.Name = "label3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 18
$System_Drawing_Size.Width = 202
$label3.Size = $System_Drawing_Size
$label3.TabIndex = 4
$label3.Text = "Input path and filename"

$form1.Controls.Add($label3)

$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,5,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 54
$System_Drawing_Point.Y = 23
$label1.Location = $System_Drawing_Point
$label1.Name = "label1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 18
$System_Drawing_Size.Width = 328
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 2
$label1.Text = "1. Read CSV, sort and convert"
$label1.TextAlign = 16

$form1.Controls.Add($label1)


$button1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 307
$System_Drawing_Point.Y = 137
$button1.Location = $System_Drawing_Point
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 67
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 1
$button1.Text = "Go"
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($convert_csv)

$form1.Controls.Add($button1)

$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 90
$System_Drawing_Point.Y = 72
$textBox1.Location = $System_Drawing_Point
$textBox1.Name = "textBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 22
$System_Drawing_Size.Width = 202
$textBox1.Size = $System_Drawing_Size
$textBox1.TabIndex = 0
$textBox1.Text = "c:\import.csv"

$form1.Controls.Add($textBox1)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

Open in new window


appreciate for your help
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Mandy_
Mandy_

ASKER

thats nice solution