Download file from published folder

Hi,
Im trying to use “Start-UDDownload” for downloading files from a published folder but not able to get the file.

Have tried something like this:
New-UDButton -Text ‘Download Profile Picture’ -Id ‘Picturedownload’ -OnClick {
Start-UDDownload -Content “<path to file in published folder + filename>” -StringData “foo” }

Can only manage to download a simple text file which contains StringData when I press my button

Product: PowerShell Universal
Version: 1.4.6

You should be able to avoid using Start-UDDownload all together by using the download attribute. Start-UDDownload only supports text at the moment.

New-UDElement -Tag a -Attributes @{  
        href = “<path to file in published folder + filename>” 
        download = "<filename>"
}
1 Like

Thx nice to know.

Would it then be possible to put it under “new-udbutton” for getting it to work with my dashbord as a download button?

New-UDButton -Text 'Download Profile Picture'  -Id 'Picturedownload' -OnClick  {

  New-UDElement -Tag a -Attributes @{  
    href = “<path to file in published folder + filename>”
     download = "<filename>"         
  }
            
}

@LinuxGuy @adam do either of you have a completed example of this download button? I’m having issues successfully downloading a file from a button on my dashboard while using the example above.

No I dont´t. Trying the same thing as you @mtndrew11

1 Like

I’ve attempted the following but haven’t had any success just yet.
I also tried just using the RequestedPath name + the file name for the href attribute (as in “/PublishedFolder/File1.txt”)

New-UDButton -Text "Download" -OnClick  {
  New-UDElement -Tag a -Attributes @{  
     href = “C:\ProgramData\UniversalAutomation\Repository\dashboards\PublishedFolder\File1.txt”
     download = "File1.txt"
  }
}

The Start-UDDownload cmdlet works for me, but as Adam mentioned, that only supports text files. I’m aiming to ultimately have a button that the user clicks and it start a RDP session.

The HREF needs to be the URL and not the path. You also can’t use the element within the button. You may be able to style the A tag to look like a button but I would have to play around with it.

  New-UDElement -Tag a -Attributes @{  
     href = “/PublishedFolder/File1.txt”
     download = "File1.txt"
  }

Awesome. That worked for me. I was able to download a text file, JPG, and RDP file. Thanks @adam
I also added a button to the content of the UDElement to keep the button feature and create a download button:

  New-UDElement -Tag a -Attributes @{  
     href = “/PublishedFolder/File1.txt”
     download = "File1.txt"
  } -Content {
      New-UDButton -Text "Download"
  }

@LinuxGuy give this code a try!

3 Likes

@mtndrew11 worked for me as well. @adam thx for the help.

1 Like

Worked on the first try!
Thanks!!