c# how to download text from txt file from url code example

Example 1: how to download file from url using c#

using (var client = new WebClient())
{
    client.DownloadFile("http://example.com/file/song/a.mpeg", "a.mpeg");
}

Example 2: save text input into a txt file in c#

using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Linq;  
using System.Text;  
using System.Windows.Forms;  
using System.IO;  
  
namespace WindowsFormsApplication2  
{  
    public partial class Form1: Form  
    {  
        public Form1()  
        {  
            InitializeComponent();  
        }  
  
        private void button1_Click(object sender, EventArgs e)  
        {  
            TextWriter txt = new StreamWriter("C:\\demo\\demo.txt");  
            txt.Write(textBox1.Text);  
            txt.Close();  
  
        }  
    }  
}