WinRT: application for listing files outside libraries and known folders

I am working on a Metro application that displays the contents of this folder in a ListView control. MS decided that developers do not need the System.IO.Directory class and completely remove it from the framework.

I am looking for a replacement for listing files in C # in a metro style application. I checked all the enumeration samples provided by MS, and all of them seem to only list Windows libraries using the KnownFolders class, something like:

 StorageFolder picturesFolder = KnownFolders.PicturesLibrary; 

and calling the GetFilesAsync() or GetFoldersAsync() methods, depending on your needs. This is all gold, if I want to list only inside paintings or a music library. However, I am looking to list files in directories that are not in the library.

Does anyone know how this is possible in WinRT ???

+6
source share
4 answers

You, by design, are extremely limited in this area for Metro applications. The idea is that the Metro application only gets access to things that are trusted by access, so you can:

  • Local storage access specific to your application.
  • access to several well-known storage locations or
  • Access a dedicated address.

Take a look at http://msdn.microsoft.com/en-us/library/windows/apps/hh464959.aspx for an idea of ​​what you can access.

+14
source

From http://tirania.org/blog/archive/2011/Sep-15.html :

When you use C # and VB, you use the full .NET platform. But they decided to expose a smaller subset of the developer APIs to push a new vision for Windows 8.

And this new vision includes security / sandboxing systems and asynchronous programming. This is why you do not get direct access to the file system or access to sockets and why the synchronous APIs that you used for consumption are not exposed.

Now you notice that I said "exposed" and not "gone."

What they did was that they only exposed the compiler a set of APIs when you target the Metro profile. Thus, your application will not accidentally call the File.Create command. However, at runtime, the CLR will load the full class library, the one that contains File.Create, so inside the CLR it can call something like File.Create, you just don’t have access to it.

This split is similar to what was done in the past with Silverlight, where not every API was open, and where mscorlib was granted rights so that your application does not need to be secured.

Perhaps you think you can use some sort of trick (link to the GAC library instead of the link to the compiler or using reflection to get to private APIs or P / Invoking in Win32). But all of these be caught by the AppStore app for review, and you will not be able to publish your application through the Microsoft store.

You can still do everything that is ugly to hack, please, in your system. It just will not be able to publish this through the AppStore.

Thus, there may be no official way, and if there is an unofficial way, it probably will not be accepted in the application store.

In general, this makes sense: I don’t want to download a seemingly legitimate application, just to scan my hard drive and find my budget.xls table, which includes my banking / credit information.

EDIT: You can provide temporary access to protected files / folders through a WinRT file, but it must be called and selected explicitly by the user.

+10
source

You can use the StorageFolder.GetFolderFromPathAsync method to get the StorageFolder from the path.

 StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(@"C:\..."); 

Note that you may not have permission to do this for all paths on your computer.

0
source

A similar situation. Requires access to the chrome bookmark file for parsing. If you use FileOpenPicker initially, but the file that it returns may be "cached" in a future access list (?) For later searches.

0
source

Source: https://habr.com/ru/post/916352/


All Articles