zoukankan
html css js c++ java
使用WebClient进行上传文件 [ZT]
private
bool
UploadFile(
string
source,
string
targetUrl,NetworkCredential networkCredential)
{
FileStream streamSource;
Stream streamTarget;
WebClient client
=
new
WebClient();
client.Credentials
=
networkCredential;
try
{
streamSource
=
File.OpenRead(source);
}
catch
(Exception err)
{
return
false
;
}
try
{
Uri url
=
new
Uri(targetUrl);
streamTarget
=
client.OpenWrite(url,
"
PUT
"
);
}
catch
(Exception err)
{
return
false
;
}
try
{
long
num
=
0
;
int
count
=
0
;
byte
[] buffer
=
new
byte
[
512
];
while
(num
<
streamSource.Length)
{
count
=
streamSource.Read(buffer,
0
,
512
);
streamTarget.Write(buffer,
0
, count);
num
+=
count;
}
streamTarget.Close();
streamSource.Close();
return
true
;
}
catch
(Exception err)
{
return
false
;
}
}
查看全文
相关阅读:
数据库中char、varchar、varchar2、nvarchar之间的关系
Oracle中scott用户下基本表练习SQL语句
判断一个数是否是素数
阿里P7前端需要哪些技能
react Native 踩坑记录
流程节点(2018.7.31)
在centos7下手工安装和配置Nginx
微信公众号开发
nodejs 实战
数据库权限表的设计
原文地址:https://www.cnblogs.com/RobotTech/p/928856.html
最新文章
The Boot Process at a Glance x86/x64系统启动过程解析
PCIe
开源是个巨大的坑,谁来帮帮我
重新生成索引和重新组织索引
淘宝npm镜像
T4扩展程序
C#中的协变与抗变
using关键字
.net core2.0入门使用EF
avalon学习教程
热门文章
服务器数据库堵塞造成假死
BootStrap-table 复选框默认选中(checkbox)
ASP.NET MVC中在 @RenderBody() 或者 @Html.Partial()中需要使用引入外部js,css
Tomcat Can't load AMD 64-bit .dll on a IA 32
将博客搬至CSDN
hibernate的查询 (比较get 与load)
hibernate open session in view 抛出异常解决方法
hibernate事务管理 (jdbc jta)
hibernate的各种保存方式的区别 (save,persist,update,saveOrUpdte,merge,flush,lock)
myeclipse更改类或者是配置文件不用重启tomcat的方法
Copyright © 2011-2022 走看看