Menu

Save file using live url

Hello Friend,

Here we have create one function to save file using live url.


   public void SaveFile(string url)
        {
            string fileName = System.IO.Path.GetFileName(url);//Get file name 
            string descFilePath = System.IO.Path.Combine("d:/", fileName);
            //Destination Path
            try
            {
                byte[] fileData = null;
                using (WebClient client = new WebClient())
                {
                    fileData = client.DownloadData(url);
                }
                using (FileStream fs = new FileStream(descFilePath, FileMode.OpenOrCreate))
                {
                    fs.Write(fileData, 0, fileData.Length);
                    //File Save
                }
          }
          catch (Exception ex)
          {
          }
  }       


No comments

Leave a Reply


6 − = 3

Categories