Код: Выделить всё
formWebView2.webView2.CoreWebView2.Profile.DefaultDownloadFolderPath = filePath;Код: Выделить всё
TaskCompletionSource downloadTaskCompletionSource = new TaskCompletionSource();
formWebView2.webView2.CoreWebView2.DownloadStarting += delegate (object sender, CoreWebView2DownloadStartingEventArgs args) {
args.DownloadOperation.StateChanged += delegate (object sender, Object e) {
switch (args.DownloadOperation.State) {
case CoreWebView2DownloadState.Completed:
downloadTaskCompletionSource.TrySetResult(true); // Continue when the download is completed
break;
}
};
};
// Click on the DOWNLOAD button
string script = @"(function(){
var status = 'ERROR';
const downloadDataButtons = document.getElementsByClassName('historical-data__controls-button--download historical-download');
if (downloadDataButtons.length == 1) { // Check to make sure there is only one such button
downloadDataButtons[0].click();
status = 'OK';
}
return status;
})();";
string javaScriptResponse = await formWebView2.webView2.ExecuteScriptAsync(script);
await downloadTaskCompletionSource.Task; // Wait for the file to finish downloading
Код: Выделить всё
using (MemoryStream memoryStream = new MemoryStream(webClient.DownloadData(url))) {
memoryStream.Position = 0; // Start the memoryStream at the beginning
using (StreamReader streamReader = new StreamReader(memoryStream)) {
for (int lineNumber = 0; lineNumber < memoryStream.Length; lineNumber++) {
String line = streamReader.ReadLine();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/780 ... h-webview2
Мобильная версия