Could anyone please help me convert this code snippet to it's .net core equivalent?
Uri uri = new Uri(url);
string filename = System.IO.Path.GetFileName(uri.LocalPath);
string extension = Path.GetExtension(filename);
string tempFilepath = Path.GetTempFileName() + extension;
try
{
WebClient webClient = new WebClient();
webClient.DownloadFile(url, tempFilepath);
if (new FileInfo(tempFilepath).Length > 0)
{
return tempFilepath;
}
else {
return null;
}
}
catch (WebException e)
{
return null;
}
catch (NotSupportedException e)
{
return null;
}
Actually, this code was previously in an application which was writte in .net 4.6. Then some time ago, we stopped using that app. Now I am developing another app in .net core and will be doing exact same thing. So I wonder how would I do this using .net core? What is the alternate to DownloadFile method in HttpClient?