下载服务器端的图片和下载excel
#region 下载
/// <summary>
/// 下载资源
/// </summary>
public void Download()
{
SaveFileDialog open = new SaveFileDialog();
open.Filter = "*.xls;*.xlsx;*.xl;*.xlsn|*.xls;*.xl;*.xlsn;*.xlsx"; //保存图像类型
string path = "http://192.168.3.63:9999/UpLoad/Default/案例.xlsx";
Uri uri = new Uri(path);
open.FileName = uri.Segments[uri.Segments.Length - ];
DialogResult result = open.ShowDialog();
if (!string.IsNullOrWhiteSpace(open.FileName) && result == DialogResult.OK)
{
if (DownloadImage("http://192.168.3.63:9999/UpLoad/Default/案例.xlsx", open.FileName))
{
MessageBox.Show("下载成功!");
}
}
}
/// <summary>
/// 下载服务器文件至客户端
/// </summary>
/// <param name="urlString">被下载的文件地址,绝对路径</param>
/// <param name="saveDir">另存放的目录</param>
/// <returns>b</returns>
public bool DownloadImage(string urlString, string saveDir)
{
WebClient client = new WebClient();
FileStream fsStr = null;
HttpWebResponse res = null;
try
{
int n = urlString.LastIndexOf("/");
string fileName = urlString.Substring(n + , urlString.Length - n - ); //直接下载到桌面
//client.DownloadFile(urlString, fileName); //下载到指定目录
Stream stream = client.OpenRead(urlString);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(urlString);
res = (HttpWebResponse)req.GetResponse();
long len = res.ContentLength; BinaryReader r = new BinaryReader(stream);
byte[] byteS = r.ReadBytes((int)len); fsStr = new FileStream(saveDir, FileMode.OpenOrCreate, FileAccess.Write);
fsStr.Write(byteS, , (int)len);
fsStr.Close();
res.Close();
stream.Close();
return true;
}
catch (Exception err)
{
return false;
}
finally
{
if (fsStr != null)
{
fsStr.Close();
fsStr.Dispose();
}
if (res != null)
{
res.Close();
}
}
}
#endregion
#region 下载
/// <summary>
/// 下载图片
/// </summary>
/// <param name="path">下载路径</param>
/// <param name="save">保存路径</param>
//private void DownloadImage(string path, string save)
//{
// Stream stream = null;
// if (path != null)
// {
// Uri uri = new Uri(path);
// try
// { // if ("http".Equals(uri.Scheme, StringComparison.CurrentCultureIgnoreCase))
// {
// //如果是HTTP下载文件
// WebClient wc = new WebClient();
// stream = new MemoryStream(wc.DownloadData(uri));
// }
// else if ("file".Equals(uri.Scheme, StringComparison.CurrentCultureIgnoreCase))
// {
// stream = new FileStream(@path, FileMode.Open, FileAccess.Read);
// } // //Image image = new Bitmap(stream);
// //mage.Save(save);
// MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// }
// catch (Exception e)
// {
// System.Windows.MessageBox.Show(e.Message);
// }
// }
//}
#endregion
下载服务器端的图片和下载excel的更多相关文章
- android 图片网络下载github开源框架之Universal-Image-Loader
最近在做妙趣剪纸项目,剪纸应用项目链接.发扬传统文化,大家多多关注. 需要自己搭建服务器,我用的是新浪sae,简直秒杀京东云几条街,把图片放在网上下载,但是图片经常下载要遇到很多问题,包括oom等.所 ...
- thinkphp3.2.3 excel导出,下载文件,包含图片
关于导出后出错的问题 https://segmentfault.com/q/1010000005330214 https://blog.csdn.net/ohmygirl/article/detail ...
- C++根据图片url下载图片
需要使用到URLDownloadToFile()函数,该函数在头文件<urlmon.h>中声明. URLDownloadToFile()函数的定义如下: HRESULT URLDownlo ...
- Unity3D图片的下载及保存
Unity3D图片的下载及保存 分类: Unity3D 2013-06-24 15:03 3609人阅读 评论(2) 收藏 举报 Unity3D图片URL 代码如下: [csharp] view pl ...
- [C#基础实例]指定地址解析图片并下载
需求:查找页面图片并下载至本地: 实现: 首先:读取通过网络html内容,并用正则表达式查找图片地下. 其次:使用WebRequest.Create创建图片请求. 最后:把获取图片网络流数据通过Fil ...
- PhoneGap奇怪的现象:File FileTransfer download, 手机相册检测不到下载下来的图片(解决)
我有个从服务器下载相片的功能在使用 File FileTransfer download api时,碰到了很奇怪的现象:图片已经从服务器里下载了,手机文件夹里也可以看到下载过来的图片,但是我的手机相册 ...
- DELL服务器引导光盘图片及下载链接
DELL服务器引导光盘图片及下载链接 所有的下载地址均是ftp开头的,下载时,请 拷贝下载地址,然后放到浏览器的地址栏进行下载! 各个下载地址汇总: http://search.dell.com/re ...
- php将抓取的图片链接下载到本地
备注: fclose这一步操作完成之后如果返回值是空表示下载成功,否则会返回1或者其他错误提示 这个步骤测试的时候实在yii2框架的基础上执行的,下载到的图片实在frontend目录下的web目录下( ...
- 【图文详解】python爬虫实战——5分钟做个图片自动下载器
python爬虫实战——图片自动下载器 之前介绍了那么多基本知识[Python爬虫]入门知识,(没看的先去看!!)大家也估计手痒了.想要实际做个小东西来看看,毕竟: talk is cheap sho ...
随机推荐
- Java基础之写文件——将素数写入文件中(PrimesToFile)
控制台程序,计算素数.创建文件路径.写文件. import static java.lang.Math.ceil; import static java.lang.Math.sqrt; import ...
- Fixed 鸟粪一样的TreeView下的NodeMouseDoubleClick Bug
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { Rectangl ...
- MVC1
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
.NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...
- 用于sql server启动的账户
用于启动和运行 SQL Server 的启动帐户可以是域用户帐户.本地用户帐户.托管服务帐户.虚拟帐户或内置系统帐户. 若要启动和运行 SQL Server 中的每项服务,这些服务都必须有一个在安装过 ...
- java io读书笔记(5) Writing Bytes to Output Streams
outputstream类是所有的字符输出类的父类,他是一个抽象类. 对于OutputStream类来说,其最基础的方法就是:write(). public abstract void write(i ...
- PostgreSQL9.1 upgrade to PostgreSQL9.5rc1
PostgreSQL9.1.0 upgrade to PostgreSQL9.5rc1 安装PG9.1端口为5432 [pgup@minion1 pg]$ ls postgresql-9.1.0.ta ...
- JavaScript——DOM操作——Window.document对象
一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunment.getElementById(&qu ...
- [reprint]malloc与calloc的区别
[http://blog.163.com/crazy20070501@126/] 转自某自由人的博客: malloc与calloc的区别 函数malloc()和calloc()都可以用来动态分配内存空 ...
- editPlus修改默认的文件编码