0
votes

I setup WebView2 to have a virtual host and I am able to access an image based on a URL.

The problem that i have is that i need get the number of files stored in the "virtual folder". Is that possible with WebView2?

var env = await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(userDataFolder: MyCacheDirectory);
await this.EnsureCoreWebView2Async(env);
this.CoreWebView2.SetVirtualHostNameToFolderMapping(hostName, MyCacheDirectory, CoreWebView2HostResourceAccessKind.DenyCors);
//How do i access MyCacheDirectory via WebView2?
1
This is not a matter of WebView2 or any other web client. The decisive factor is wheter or not the server exposes such listing. - Alejandro

1 Answers

2
votes

Its not possible via WebView2 APIs but it is possible via .NET APIs.

SetVirtualHostNameToFolderMapping lets you specify a local folder and a hostname and then allows you to access the files in that local folder and subfolders as https URIs using the provided hostname. WebView2 does not provide any metadata about the files or folders available via the virtual host name mapping.

However, you can use .NET file system APIs to count the number of files in the folder you provided to SetVirtualHostNameToFolderMapping. For example:

System.IO.Directory.GetFiles(MyCacheDirectory).Length;

See File count from a folder for more information on counting files in a folder.