0

When I try to download an excel file using C# Web client the default saved location is the bin folder

  public void downloadCSVResult(string ssid,string thoken)
    {


        using (var client = new WebClient())
        {
            client.Credentials = new NetworkCredential(ssid, thoken);
            string url= "https://api.twilio.com/2010-04-01/Accounts/"+ssid+"/SMS/Messages.csv";
            client.DownloadFile("https://api.twilio.com/2010-04-01/Accounts/"+ssid+"/SMS/Messages.csv", "Messages.csv");

        }
        Process.Start(@"\\SMSLogs");

I have added a folder called SMSLogs inside the project and I want to download to this specific folder

But When I try to download and to open the folder using explorer :

client.DownloadFile("https://api.twilio.com/2010-04-01/Accounts/"+ssid+"/SMS/Messages.csv", "SMSLogs\\Messages.csv");

        }
        Process.Start(@"\\SMSLogs");

I receive an error

{"Could not find a part of the path 'C:\SMSLogs\Messages.csv'."}

But I don't want to save it in the C: directory because once I give the application to the client , It be good to have a directory called SMSLogs and inside of it the excel file

What I'm doing wrong?

Thanks

napi15
  • 2,354
  • 2
  • 31
  • 55

1 Answers1

0

I think this is what you are looking for. Here is a good reference for routing to the base folder in an application: Best way to get application folder path.

 string filePath = Path.GetDirectoryName(Application.ExecutablePath) + @"\SMSLogs\"; 
Community
  • 1
  • 1
TJM
  • 92
  • 6