I'm working with ASP.NET Core and try to download a file to an absolute path.
But the problem I have is that the file always gets downloaded to the project directory and the filename itself gets the name of the whole path.
My Code:
string path = @"C:\Users\User\file.txt";
string url = "https://example.com/file.txt";
using (var client = new WebClient())
{
client.DownloadFile(url, path);
}
With this code the file gets then saved in the project folder with the file name C:\Users\User\file.txt, instead of being saved in the directory C:\Users\User with the file name file.txt.
The backslashes and the colon get replaced with some special characters, because they are not allowed in the filename.