I'm creating a form for Sharefile but I have a problem passing $LocalData to the second function.
In theory the script will upload the file to ShareFile and add notes the Upload-File function. It uses $LocalData to identify the file to upload, this part works.
The second part is supposed to grab $LocalData, from there I separate out the file name and compare that to a list of files on ShareFile. When it finds a match it generates a download link. The only problem is $LocalData is not getting passed to the second function Get-Link.
So far, I tried specifying $LocalData as a Param, calling the function with $LocalData (Get-Link $LocalData) and a few other crazy things that popped up in my mind. It appears to lose the data Stream after executing the first function. Am I missing something?
I know the Get-Link portion works, befause when I manually assign $LocalData it processes the function.
$SFLinkFormFileBtn.Add_Click(
{
Add-Type -AssemblyName System.Windows.Forms
$SFLinkFormFClick = New-Object System.Windows.Forms.OpenFileDialog
$SFLinkFormFClick.Title = "Please Select File"
$SFLinkFormFClick.InitialDirectory = $InitialDirectory
$SFLinkFormFClick.filter = “All files (*.*)| *.*”
If ($SFLinkFormFClick.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
$LocalData = $SFLinkFormFClick.FileName
}
Upload-File
Get-Link
# [VOID]$SFLinkForm.Close()
}
)
RetoredGeek you are correct.
Added to start of function:
Function Get-Link { Write-Host $LocalData Pause
returned:
PS C:\Users\erobins> C:\Stuff\ShareFileAutomation.ps1 False C:\a\b\ARP VPN First Login.docx
I created a test file from your code to verify that it gets the value from the dialog:
Clear-Host
$SFLinkFormFClick =
New-Object System.Windows.Forms.OpenFileDialog
$SFLinkFormFClick.Title = "Please Select File"
$SFLinkFormFClick.filter = “All files (*.*)| *.*”
If ( $SFLinkFormFClick.ShowDialog() -eq
([System.Windows.Forms.DialogResult]::OK)) {
$LocalData = $SFLinkFormFClick.FileName
}
"$LocalData"
The output shows it does.
G:\BEKDocs\Scripts\Test\WGFileList.csv
PS>
So your problem is in not passing the argument to your other functions and/or how you retrieve that data in those functions.
I'd suggest you set breakpoints in the called functions before the first executable line of code so you can see if the value is getting passed correctly.