wpf download file from website from wpf application edit button Edit

Pooran Prasad Rajanna | calendar 08 September 2020 | 2831

simple.. below function downloads the file from the website, reads the content assuming it is a text file, and returns the content.

WPF Sample Code

private string DownloadTemplate(string baseurl, string filename)
            string strtemplatedata = "";

                WebClient Client = new WebClient();
                Client.DownloadFile(baseurl   filename, filename);

                StreamReader re = File.OpenText(filename);
                string input = null;
                while ((input = re.ReadLine()) != null)
                    strtemplatedata = strtemplatedata   input;

            catch (Exception ex)
               MessageBox.Show("Error while fetching the file" filename "\r\n"   ex.Message   "\r\n"   ex.StackTrace);                              

            return strtemplatedata;

Use System.Net namespace before executing.