在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
直接看代码吧: /// <summary> /// 下载文件 /// </summary> /// <param name="filePath">文件地址</param> /// <returns></returns> public ActionResult DownLoadFile(string filePath) { if (filePath == null) { return null; } //string UrlString = "http://123.123.123.123/abc/123.pdf"; int startIndex = filePath.LastIndexOf("/"); string fileName = filePath.Substring(startIndex + 1); byte[] fileData; try { WebRequest.Create(filePath); } catch (Exception ex) { //To do something return null; } try { using (WebClient client = new WebClient()) { fileData = client.DownloadData(filePath); return File(fileData, "text/plain", fileName); } } catch (Exception ex) { //To do something return null; } }
|
请发表评论