下载

/// <summary>
/// 下载文件
/// </summary>
/// <param name="URL">下载文件地址</param>
/// <param name="Filename">下载后另存为(全路径)</param>
private bool DownloadFile(string URL, string filename)
{
try
{
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create(URL);
System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse) Myrq.GetResponse();
System.IO.Stream st = myrp.GetResponseStream();
System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
byte[] by = new byte[];
int osize = st.Read(by, , (int) by.Length);
while (osize > )
{
so.Write(by, , osize);
osize = st.Read(by, , (int) by.Length);
}
so.Close();
st.Close();
myrp.Close();
Myrq.Abort();
return true;
}
catch (System.Exception e)
{
return false;
}
}

解压Zip文件

下面代码主要用到了SharpZipLib的库

private string UnZip(string entryname, ZipFile zf)
{
var cover = zf.GetEntry(entryname);
if (cover == null)
{
return null;
}
string filepath = System.AppDomain.CurrentDomain.BaseDirectory + @"pic\";
string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + RY.Common.DirectoryAndFile.GetFileExt(entryname); string name = filepath + filename;
using (FileStream writer = System.IO.File.Create(name)) //解压后的文件
{
var stream = zf.GetInputStream(cover);
int bufferSize = * ; //缓冲区大小
int readCount = ; //读入缓冲区的实际字节
byte[] buffer = new byte[bufferSize];
readCount = stream.Read(buffer, , bufferSize);
while (readCount > )
{
writer.Write(buffer, , readCount);
readCount = stream.Read(buffer, , bufferSize);
}
writer.Close();
}
return "pic/" + filename;
}

使用C#下载网络文件的更多相关文章

  1. JAVA多线程下载网络文件

    JAVA多线程下载网络文件,开启多个线程,同时下载网络文件.   源码如下:(点击下载 MultiThreadDownload.java) import java.io.InputStream; im ...

  2. Java读取并下载网络文件

      CreateTime--2017年8月21日10:11:07 Author:Marydon import java.io.ByteArrayOutputStream; import java.io ...

  3. python下载网络文件

    python下载网络文件 制作人:全心全意 下载图片 #!/usr/bin/python #-*- coding: utf-8 -*- import requests url = "http ...

  4. DELPHI TDownLoadURL下载网络文件

      DELPHI XE6 FMX 附件:http://files.cnblogs.com/xe2011/IDHttp_fmx.7z unit Unit1; interface uses //引用 Vc ...

  5. 【python】下载网络文件到本地

    # 下载网络图片文件到本地 import urllib.request rsp=urllib.request.urlopen("http://n.sinaimg.cn/ent/transfo ...

  6. java 下载网络文件

    1.FileUtils.copyURLToFile实现: import java.io.File; import java.net.URL; import org.apache.commons.io. ...

  7. python使用wget下载网络文件

    wget是一个从网络上自动下载文件的自由工具.它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理. ubuntu 安装wget pip install wget 从网络或本地硬盘下载文件(并 ...

  8. 解决FTPClient下载网络文件线程挂起问题

    今天在windows上调试FTP下载文件时,出险线程假死,代码如下: if (inputStream != null) { byte[] data = null; ByteArrayOutputStr ...

  9. C#限速下载网络文件

    代码: using System; using System.Collections.Concurrent; using System.Collections.Generic; using Syste ...

  10. 网络编程(一):用C#下载网络文件的2种方法

    使用C#下载一个Internet上的文件主要是依靠HttpWebRequest/HttpWebResonse和WebClient.具体处理起来还有同步和异步两种方式,所以我们其实有四种组合. 1.使用 ...

随机推荐

  1. Flex打印功能FlexPrintJob调用

    收藏下很详细的学习资料 http://wenku.baidu.com/view/b3d4f40702020740be1e9bf8.html import mx.printing.FlexPrintJo ...

  2. [转]linux中如何安装软件?

    Linux下软件的安装与卸载     在Windows下安装软件时,只需运行软件的安装程序(setup.install等)或者用zip等解压缩软件解开即可安装,运行反安装程序 (uninstall.u ...

  3. eclipse 技巧

    1. eclipse中xml中提示需有xsd文档 如在线eclipse将自动网络获取.xsd 否则 手动本地添加(在xml catalog参数设置选项) 2.当明确实现功能时,可将已有方法抽取成接口, ...

  4. Win7x64_chromeX86_相关路径

    1. C:\Users\33\AppData\Local\Google 里面有2个文件夹:“Chrome”.“CrashReports” 2. C:\Program Files (x86)\Googl ...

  5. web设计经验<一> 提升移动设备响应式设计的8个建议

    今天看到一些关于web设计的一些建议和设计经验,拿出来分享分享. 第一篇: 提升移动设备响应式设计的8个建议 一.直观性和易用性 在使用移动设备时,对于杂乱.复杂或者不直观的设计造成的混乱不佳的用户体 ...

  6. sqlplus入门基础语句

    关于Oracle 首先Oracle一个数据库由若干个表空间组成,每个表空间由若干个数据文件(或设备)组成,每个数据文件由若干个盘区组成,每个盘区由若干个block组成.这是Oracle的物理结构. 逻 ...

  7. [精品推荐]Android Studio插件整理

    GOOD 现在Android的开发者基本上都使用Android Studio进行开发(如果你还在使用eclipse那也行,毕竟你乐意怎么样都行).使用好Android Studio插件能大量的减少我们 ...

  8. OpenGL的gluLookAt和glOrtho的关系

    OpenGL的gluLookAt和glOrtho的关系 一直不明白gluLookAt()和glOrtho()两者之间的关系:gluLookAt()是观察变换,glOrtho()是正交投影.glLook ...

  9. FATAL ha.BootstrapStandby: Unable to fetch namespace information from active NN at ***

    This problem (Unable to fetch namespace information from active NN) occurs, because the active namen ...

  10. 每日一笔记之2:QT之坐标系统:

    以前一直多单片机开发,也没怎么使用过大的显示器,第一次学习,备忘: QT画图系统. 绘图,通过QPainter类实现. Qt的绘图系统对底层函数进行了良好的封装,使得在屏幕和设备的绘图功能可能使用相同 ...