I'm trying to download file from URL using WebClient
, the problem is that the function .DownloadFile()
requiring URL, and name that will be given to the saved file, but when we access to the URL it already has the file name.
How can I keep the file name as it is in the URL?
Instead of parsing the url I suggest using function Path.GetFileName():
string uri = "http://yourserveraddress/fileName.txt";
string fileName = System.IO.Path.GetFileName(uri);
WebClient client = new WebClient();
client.DownloadFile(uri, fileName);