【项目实战】--Office文件导出
2015-05-31 22:10
344 查看
文件的下载:
try{ string savePath = ""//保存路劲 downFileUrl = "";//下载文件链接地址 WebClient wcClient = new WebClient(); WebRequest webReq = WebRequest.Create(downFileUrl); WebResponse webRes = webReq.GetResponse(); int fileLength = webRes.ContentLength; Stream srm = webRes.GetResponseStream(); StreamReader srmReader = new StreamReader(srm); byte[] bufferbyte = new byte[fileLength]; int allByte = (int)bufferbyte.Length; int startByte = 0; while (fileLength > 0) { //Application.DoEvents(); int downByte = srm.Read(bufferbyte, startByte, allByte); if (downByte == 0) { break; }; startByte += downByte; allByte -= downByte; } if (!File.Exists(savePath)) { string[] dirArray = savePath.Split('\\'); string temp = string.Empty; for (int i = 0; i < dirArray.Length - 1; i++) { temp += dirArray[i].Trim() + "\\"; if (!Directory.Exists(temp))Directory.CreateDirectory(temp); } } FileStream fs = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(bufferbyte, 0, bufferbyte.Length); srm.Close(); srmReader.Close(); fs.Close(); } catch (WebException ex) { throw ex; }
相关文章推荐
- WorldWind源码剖析系列:角度类Angle
- [Java5新特性]自动装箱/拆箱
- StringBuilder常用方法
- 五分钟一个设计模式之组合模式
- Python学习日记---字符串
- LINUX-软件安装(二)
- 生产环境超时库存回收优化
- ITOO3.0-我们的项目做的到底如何?
- 占座2
- 数据库数据优化故事多
- 【转】ubuntu安装ftp服务器
- [Java5新特性]自动装箱/拆箱
- WorldWind源码剖析系列:数学引擎类MathEngine
- IBATIS事务处理
- 链表中倒数第k个结点
- [DP]乘电梯
- touch事件的派发与传递
- 杭电ACM1398——Square Coins~~母函数
- 占座4
- 占座3