Download csv file from url without filename in c# console

Gowsalya 21 Reputation points
2022-07-25T12:03:30.997+00:00

Hi,
I am trying to download a csv file from url without filename.
The filename differs so the url will not have filename.

Can anyone guide me.

Thanks in advance.

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,276 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 112.5K Reputation points
    2022-07-25T14:16:31.333+00:00

    Maybe you need something like this:

    string url = @". . ."; // the URL without file name  
      
    using( WebClient wc = new WebClient( ) )  
    {  
        // download and save to local file  
        wc.DownloadFile( url, "MyFile.csv" );  
      
        // or download to a string variable  
        string csv = wc.DownloadString( url );  
        . . .  
    }  
    
    2 people found this answer helpful.
    0 comments No comments

  2. Olaf Helper 40,901 Reputation points
    2022-07-25T12:11:28.963+00:00

    I am trying to download a csv file from url without filename.

    How could that be possible, without a filename?
    There may be some some thousand files on the server and you want to download one specific; without using the filename?