0

So, I have this code i am programming under a button. When pressed, the user is asked if they want to download the newest File. If yes, then download it and the download location is supposed to be: Documents\Fiddler2 (You Get this Folder created when Installing Fiddler Classic).

However, after several different attempts, the file is only downloaded to the Documents Folder and needs to download to the Documents\Fiddler2 Folder. What am I doing wrong?

        private void button4_Click(object sender, EventArgs e)
        {
                string title = "Check For New Version.";
                string question = "Would you like to Check for any Updates?";
                string url = "www.google.com";
                if (DialogResult.Yes ==
                 MessageBox.Show(this, question, title,MessageBoxButtons.YesNo,MessageBoxIcon.Question))
                {
                string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string path2 = Path.Combine(path, @"Fiddler2");
                MessageBox.Show(path2);
                Directory.SetCurrentDirectory(path2);
                using (var client = new WebClient())
                {
                    client.DownloadFile("https://drive.google.com/file/d/13K2IEH-FNQ2HhqAlvaYO3sEZoeWOtPMN/view?usp=sharing", "test.png");
                }
            }
  • The folder where test.png is store is relative to where the c# executable is located. So to put in different folder like parent use ".\..\test.png" See : https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=netcore-3.1 – jdweng Oct 03 '20 at 01:26
  • It doesn't work. –  Oct 03 '20 at 19:33
  • Did it go into a different folder or fail? – jdweng Oct 03 '20 at 20:29
  • It's okay, I Figured it out. It just went into the same folder but after trial and error. I got it to work via the Path.Combine method! Thank you SOO Much! –  Oct 03 '20 at 20:36
  • If you would use `DownloadFileAsync` you could specify the destination directory: https://stackoverflow.com/a/58060551/150978 – Robert Oct 06 '20 at 16:10

0 Answers0