According file url, download the file to a local

///  <Summary> 
        /// The file url, download the file to a local
         ///  </ Summary> 
        ///  <param name = "fileURL"> File Address </ param> 
        ///  <param name = "path "> save path </ param> 
        public  static  String DownFile ( String fileURL, String path) 
        { 
            IF (! Directory.CreateDirectory (path) Directory.Exists (path));
             var fileName = fileUrl.Substring (fileUrl.LastIndexOf ( " / " ) + 1 );
            var filePath = path + "/" + fileName;
            WebClient wc = new WebClient();
            if (!File.Exists(filePath))
                wc.DownloadFile(fileUrl, filePath);
            else
            {
                filePath = path + "/" +Guid.NewGuid().ToString() + fileName;
                wc.DownloadFile(fileUrl, filePath);
            }
            return filePath;
        }

 

Guess you like

Origin www.cnblogs.com/sanday/p/11367253.html