C#网络文件保存本地

    xiaoxiao2022-07-13  207

    string SaveFile(string address, ref string fileName) { try { var path = sericeURL + @"\tempFile\" + DateTime.Now.ToString("yyyyMMdd") + @"\"; var filePath = path + fileName; if (!Directory.Exists(path)) Directory.CreateDirectory(path); if (File.Exists(filePath)) { fileName = "I" + fileName; filePath = path + fileName; return SaveFile(address, ref fileName); } using (WebClient client = new WebClient()) { // address:从中下载数据的 URI,www.xxxx.com/xx.jpg // filePath:保存地址 URI,C:\\tempFile\\xx.jpg client.DownloadFile(address, filePath); } return filePath; } catch (Exception ex) { LogHelper.Log.Error("文件保存异常:", ex); throw ex; } }

         

    最新回复(0)