It’s typical to access data from shared folders yes, but not served via web links like this, in fact the link I shared earlier actually highlights this and I suspect it’s the exact reason you’re encountering issues:
Note that this is most useful in IE and Outlook/Word. It won’t work in Chrome or Firefox, intentionally - the link will fail silently. Some words from the Mozilla team:
For security purposes, Mozilla applications block links to local files (and directories) from remote files.
And less directly, from Google:
Firefox and Chrome doesn’t open “file://” links from pages that originated from outside the local machine. This is a design decision made by those browsers to improve security.
The Mozilla article includes a set of client settings you can use to override this behavior in Firefox, and there are extensions for both browsers to override this restriction.
Note that this stackoverflow was actually written in 2009, so I wouldnt be supprised if IE/Edge is also blocking these too.
Web servers when serving links, typically only provide access internally to what is in scope from a security perspective, and file type may also pose an issue if it’s not a standard html link, which is why you’d need to either host the file in a published folder, or on another web service such as sharepoint etc and link to that.
Just to be sure, I also tested the following methods and was unable to do what you were trying:
New-UDButton -Href "D:\test.txt" -Text "test1"
New-UDHTML -Markup "<a href='D:\test.txt' target='_blank'>test2</a>"
New-UDLink -Text "test3" -Url "D:\test.txt" -OpenInNewWindow
New-UDHtml -Markup "<br>"
New-UDButton -Text "test4" -OnClick {
Start-UDDownload -Url "D:\test.txt"
}
New-UDHtml -Markup "<br>"
New-UDButton -Text "test5" -OnClick {
Invoke-UDRedirect -Url "D:\test.txt" -OpenInNewWindow
}
tested with and without the file:// format.
Here’s one solution you can use if moving the file is not possible, in testing this worked fine for me from a network path:
New-UDButton -Text "test5" -OnClick {
Copy-Item -Path "\\unc path\Test.txt" -Destination "$Repository\..\PublishedFolder\Test.txt" -force
Invoke-UDRedirect -OpenInNewWindow -Url "pubPath/Test.txt"
Sleep 3
Remove-Item "$Repository\..\PublishedFolder\Test.txt" -force -Confirm:$false
}
Just note that this obviously requires the PSU server / whatever context it’s running in to have access to those paths. Although it’s a hacky workaround imo, personally I’d rather just serve the file from published folders directly or shift it to sharepoint and link to that if others need to use it outside of PSU.