0

I am trying to make a C# app that would download and save file from the given website as csv file. However instead of downloading the correct file, it keeps saving source code of the page inside of the downloaded file. What am I doing wrong? I have tried CookiesAwareWebClient as well however it gives the same result.

private void button1_Click(object sender, EventArgs e)
    {
        NameValueCollection nvc = new NameValueCollection();
        nvc.Add("ctl00_MainContent_InstType3ListBox_scrollTop", "0");
        nvc.Add("ctl00_MainContent_KommuneListBox_scrollTop", "0");
        nvc.Add("ctl00$MainContent$InstType3ListBox", "-1");
        nvc.Add("ctl00$MainContent$KommuneListBox", "-1");
        nvc.Add("ctl00$MainContent$UdtrękButton", "Dan+udtręk+til+CSV-format");
        byte[] result = TestPost("http://statistik.uni-c.dk/instregudtraek/", nvc);
        Debug.WriteLine("Downloading file...");
        File.WriteAllBytes("C:\\Users\\wind_spirit\\Downloads\\bar.csv", result);
    }
    private byte[] TestPost(string url, NameValueCollection nvc)
    {
        WebClient webClient = new WebClient();
        byte[] response = webClient.UploadValues(url, "POST", nvc);
        return response;
    }

0 Answers0