public DownloadData ( System address ) : byte[] | ||
address | System | |
return | byte[] |
using System; using System.Net; class Program { static void Main() { WebClient client = new WebClient(); byte[] imageBytes = client.DownloadData("https://example.com/image.png"); string filePath = @"C:\Users\User\Desktop\image.png"; System.IO.File.WriteAllBytes(filePath, imageBytes); } }
using System; using System.Net; using System.Text; class Program { static void Main() { WebClient client = new WebClient(); byte[] fileBytes = client.DownloadData("https://example.com/data.txt"); string fileContents = Encoding.UTF8.GetString(fileBytes); Console.WriteLine(fileContents); } }The package library used in these examples is System.Net, which is included in the .NET Core and .NET Framework.