Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using client.DownloadFile();

Tags:

c#

I'm using client.DownloadFile(); for my console project.. now my question is: if my command goes like this:

client.DownloadFile(http://url.com/random-name, "filename")

what i need is instead of downloading the file and save it as "filename" i want the filename to be "what ever the random file name is" is that possible?

like image 264
Bxcb Sbdsb Avatar asked Mar 27 '26 18:03

Bxcb Sbdsb


1 Answers

Get the filename using Path.GetFileName. You can get the AbsoluteUri property of your URI, or just pass the full URI yourself like you've done in your post.

string filename = System.IO.Path.GetFileName(myUri.AbsoluteUri); 
client.DownloadFile(myUri, filename);
like image 87
keyboardP Avatar answered Mar 30 '26 08:03

keyboardP