文件下载(一)
来源:互联网 发布:java层次遍历二叉树 编辑:程序博客网 时间:2024/05/01 15:57
使用ICSharpCode.SharpZipLib.Zip 进行解压
下载地址:www.63yi.com/winformdlldownload/ICSharpCode.SharpZipLib.dll
/// <summary>
/// 下载
/// </summary>
/// URL 源资源
/// filename 保存名
/// </summary>
#region ...///下载
int osize = 0;
public void 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();
long totalBytes = myrp.ContentLength;
System.IO.Stream st = myrp.GetResponseStream();
System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
long size = so.Length;
long totalDownloadedByte = 0;
byte[] by = new byte[1024];
osize = st.Read(by, 0, (int)by.Length);
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte;
System.Windows.Forms.Application.DoEvents();
so.Write(by, 0, osize);
osize = st.Read(by, 0, (int)by.Length);
}
so.Close();
st.Close();
}
catch (Exception)
{
throw;
}
}
#endregion
/// <summary>
/// 解压
/// </summary>
/// <param name="FileToUpZip">需要解压的资源包</param>
/// <param name="ZipedFolder">解压到的资源文件夹</param>
#region ...///解压
public static void UnZip(string FileToUpZip, string ZipedFolder)
{
if (!File.Exists(FileToUpZip))
{
return;
}
if (!Directory.Exists(ZipedFolder))
{
Directory.CreateDirectory(ZipedFolder);
}
ZipInputStream s = null;
ZipEntry theEntry = null;
string fileName;
FileStream streamWriter = null;
try
{
s = new ZipInputStream(File.OpenRead(FileToUpZip));
while ((theEntry = s.GetNextEntry()) != null)
{
if (theEntry.Name != String.Empty)
{
fileName = Path.Combine(ZipedFolder, theEntry.Name);
///判断文件路径是否是文件夹
if (fileName.EndsWith("/") || fileName.EndsWith("//"))
{
Directory.CreateDirectory(fileName);
continue;
}
streamWriter = File.Create(fileName);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
}
}
}
catch (Exception ez)
{
VarComplete.ERROR = ez + "";
}
finally
{
if (streamWriter != null)
{
streamWriter.Close();
streamWriter = null;
}
if (theEntry != null)
{
theEntry = null;
}
if (s != null)
{
s.Close();
s = null;
}
GC.Collect();
GC.Collect(1);
}
}
#endregion
- 文件下载(一)
- android 文件下载(一)
- SpringMVC文件下载(一)
- 大文件下载(一)
- C#文件下载、文件分块下载实例(一)
- 文件的上传和下载(一)
- 文件的上传和下载(一)
- IOS文件下载总结(一)
- 文件上传与下载(一)struts2
- Android文件下载案例(一)
- Java_文件上传与下载(一)
- C# 文件下载(一)同步
- 下载文件(一)
- struts2文件下载方法一
- 四极管 BIN文件下载数据结构分析(一)
- Struts2上传与下载(一)- 单文件上传
- Android文件下载含服务器端(服务器端)一
- 框架(一)struts2——文件上传与下载
- CSS开头空两格
- 网站黑白
- WinForm下载
- 上一篇 下一篇 |返回日志列表 64位系统上部署程序的过程发生Oracle数据库无法连接的问题以及解决的过程
- jquery 取值与验证
- 文件下载(一)
- 三种境界
- 都是Hibernate的hbm文件惹的祸
- 提取Microsoft.ReportViewer.ProcessingObjectModel 的一段脚本
- WINCE下telnet,FTP及网络共享的使用方法
- oracle 同时更新(update)多个字段多个值
- Struts的ActionForm中不同类型属性的使用方法总结
- 常用GCC 编译选项
- openGL坐标系