'C# WebClient.DownloadFile to specific path

Hi i'm trying to download a png file and place it in a custom location and i have tried adding to the line but wc.DownloadFile does not allow 3 arguments. does anyone have a suggestion? (rookie programmer)

if i change wc.DownloadFile to wc.DownloadFileAsync it gives me an error on y[2]

                string lookat = args[0];
                string[] exploded = lookat.Split('/');
                WebClient wc = new WebClient();
                wc.Proxy = new WebProxy();
                string content = wc.DownloadString(args[0]);
                Regex rx = new Regex("data-id=\"(.*)\">");
                MatchCollection matches = rx.Matches(content);
                string uri = "http://" + exploded[2] + "/v2/photo/=";

                string id = matches[0].ToString().Replace("\"", "").Replace(">", "").Replace("data-id=", "");
                content = wc.DownloadString(uri + id);
                string[] res = content.Split(new string[] { "filetobedownloaded_" }, StringSplitOptions.None);
                foreach (string s in res)
                {
                    if (s.Contains(".png"))
                    {
                        string[] y = s.Replace("\\", "").Split('"');
                        wc.DownloadFile(y[2], "filetobedownloaded_" + y[0].Replace("_png", ".jpg"));
                    }
                }


Solution 1:[1]

The DownloadFileAsync accepts Uri and not string so you should convert your download link to Uri like this:

wc.DownloadFileAsync(new Uri(y[2]), "C:\\" + "filetobedownloaded_" + y[0].Replace("_png", ".jpg"));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1