I was working on a uwp project which uses webview to display webpages. I want to save a webpage locally from a url. I tried few these how to save the webpage using c#?
But it doesn't seem to be working as the solution is for a basic windows form app.
Please, forgive if I made any mistake asking question as I'm totally new to stackoverflow.
I want to save a webpage locally from a url.
It is similar to windows form. Try to send get request to the URL, and get the buffer or HTML content. For sending get request, you could use HttpClient
. And then save the html buffer to a local file which format is .html
. For example:
HttpClient httpclient = new HttpClient();
var result = await httpclient.GetBufferAsync(new Uri("https://www.microsoft.com/en-sg/"));
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("test2.html", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBufferAsync(file, result);
After downloaded you may find the downloaded file in C:\\Users\\{username}\\AppData\\Local\\Packages\\{PackageId}\\LocalState
.
For more details about file operations please reference Files, folders, and libraries .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.