```html
How to Download a File from a URL
Using UriGetLeftPart
The first step in getting the file extension is to remove all the unnecessary parts from the URL. We can use the UriGetLeftPart method to do this.
Example
string url = "http://www.example.com/file.txt"; string fileExtension = Path.GetExtension(new Uri(url).GetLeftPart(UriPartial.Path));
Using WebClientDownloadFile
We can use the WebClientDownloadFile method to download a file from a URL.
Example
using (WebClient client = new WebClient()) { client.DownloadFile("http://www.example.com/file.txt", "file.txt"); }
```
Komentar