Creating Browse Button and getting a file's path

Hello UD Community,

I am building a dashboard which is similar to the workflow on Windows’ Control Panel - Install/Uninstall Programs. I have successfully managed to build the uninstall part (see below)

But I require your help in the install part:

  1. This sections needs a browse button which accepts an exe file or any file for now
  2. Gets the path of the file
  3. Installs the file using the path when a button is clicked.

From the forums I found out that a file can be uploaded to server with universal dashboard but one cannot get the corresponding file path in the computer. So I require your assistance in completing this work. If you require any more details, I am ready to type it out.

1 Like

Currently the “Install section” looks like this:

I just want to replace the text box with Browse dialog box and be able to get the file’s path.

Hi @npranav10
the UD-Input supports file uploads:

Check it out :slight_smile:

Thanks for the reference. I had to work around it to accomplish my task.

Here’s what I did:

New-UDInput -Title “Install Software” -SubmitText “Install” -Content {
New-UDInputField -Type binaryFile -Name Browse
} -Endpoint {
param(File) Show-UDToast -Message "About to install (File.FileName) " -Duration 5000 #Show-UDToast -Message "($File.FileName)" -Duration 5000
$fileStream = [IO.File]::Create($File.FileName)
$stream = $File.OpenReadStream()
$stream.CopyTo($fileStream)

#Show-UDToast -Message “Starting disposal” -Duration 2000
Wait-Process $fileStream.Dispose()
Wait-Process $stream.Dispose()

Start-Process “$($File.FileName)” -WarningAction SilentlyContinue -ErrorAction SilentlyContinue

}

If there’s any optimization in the code possible, you are welcome to make a reply.