0

In my UWP app, to get the path of the user's downloads folder, I am importing Shell32.dlland invoking the method SHGetKnownFolderPath with the shell folder value for downloads folder "{374DE290-123F-4565-9164-39C4925E467B}" (as mentioned in Windows 10 User Shell Folders Restore Default Paths).

Now my question is, does the above way of getting the folder path, violate any UWP recommendation? Will my app pass the certification for publishing in Microsoft store? Or will it be rejected as mentioned in the answer to this question - How to access registry key in a UWP app?

Sethu Bala
  • 457
  • 3
  • 17

2 Answers2

2

A more general answer: You can use the UserDataPaths class as a replacement for SHGetKnownFolderPath in Windows 10.

Peter Torr - MSFT
  • 11,824
  • 3
  • 18
  • 51
  • Thank you Peter. The below code gave me the required path for the current user. IReadOnlyList users = await User.FindAllAsync(UserType.LocalUser, UserAuthenticationStatus.LocallyAuthenticated); string downloadPath = UserDataPaths.GetForUser(users.FirstOrDefault()).Downloads; – Sethu Bala Oct 22 '18 at 05:55
1

For using download folder in uwp, you could use Windows.Storage Api. If you want to create file in download folder you could use the follow.

StorageFile sf = await DownloadsFolder.CreateFileAsync("testMarker");

And you could get the path of DownloadsFolder via the above file. But you could not access the file with path directly.

StorageFile sf = await DownloadsFolder.CreateFileAsync("testMarker");
ArrayList numbers = new ArrayList(sf.Path.Split(new char[] { '\\' }));
numbers.RemoveRange(numbers.Count - 2, 2);
var downloadPath = string.Join("\\", numbers.ToArray());

SHGetKnownFolderPath is not support in uwp, But you could use it in an desktop-bridge app you could call any methods before you convert your desktop app to UWP app.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • "SHGetKnownFolderPath is not support in uwp", by this words you mean my app will not pass the certification to publish in Microsoft Store? – Sethu Bala Oct 03 '18 at 04:03
  • 1
    @SethuBala Yep. APIs supported in UWP platform will be labeled as supported in UWP platform from doc. Like this API: https://learn.microsoft.com/en-us/windows/desktop/api/combaseapi/nf-combaseapi-clsidfromstring You can see this: desktop apps | UWP apps And here is the supported API list:https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis – Barry Wang Oct 03 '18 at 06:36