Support for link files in uwp

Allanjb 246 Reputation points
2020-12-06T01:45:41.793+00:00

I cannot find any support for working with shortcut files, (.lnk files) in UWP, for example FileIO and StorageFile do not support this file type.
Can you suggest how I can access System.IO from a UWP app?
I can retrieve a list of *.lnk files from a folder in a WPF or Forms app quite easily but not so in a UWP app.
As I use .lnk file extensively to represent photo's, I need this capability if I am to migrate my apps to UWP.
I currently use SHELL32 folderItem.GetLink to retrieve files from links.
I have found out that System.IO.Directory will not work with UWP apps, (tried and got an access violation)!

Update:
I have added Win32 functions: FindFirstFileEx() and FindNext() which as far as I can tell are supported by the UWP platform.
While I can access files in the installation folder I cannot access arbitrary folders without getting a Win32 error code 5, Access is denied. I have added broadFileSystemAccess to my UWP app and have file system access through settings.
Moving the files to another folder to make access easier is a last resort, I would rather retool the app in WPF.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 33,371 Reputation points Microsoft Vendor
    2020-12-07T03:18:39.39+00:00

    Hello,

    Welcome to Microsoft Q&A!

    First of all, UWP apps are running in the sandbox and it has limited file permissions. So some APIs in System.IO will be limited in UWP apps. Then UWP apps can access certain file system locations by default like application install directory, application data locations. Apps can also access additional locations through the file picker, or by declaring capabilities. For more information please refer to this document: File access permissions. This is why you got an access violation error in your app.

    So you need to have the link files placed in some locations that UWP could access.

    Thank you.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.