zoukankan
html css js c++ java
多文件上传实现
利用Request.Files对象
代码:
public
static
bool
SaveResourceFile(System.Web.UI.Page page, System.Web.HttpFileCollection hfc,
string
resourcePath)
{
for
(
int
i
=
0
; (i
<
hfc.Count); i
++
)
{
HttpPostedFile file
=
hfc.Get(i);
if
(file.ContentLength
>
0
)
{
try
{
if
(
!
Directory.Exists(page.Server.MapPath(resourcePath)))
{
DirectoryInfo di
=
Directory.CreateDirectory(page.Server.MapPath(resourcePath));
}
if
(file.FileName.LastIndexOf(
"
\\
"
)
!=
-
1
)
{
fileName
=
file.FileName.Substring(file.FileName.LastIndexOf(
"
\\
"
)
+
1
);
}
//
将输入流转换成Byte[]
byte
[] buffer
=
new
byte
[file.ContentLength];
file.InputStream.Read(buffer,
0
, buffer.Length);
//
存上传的文件
WriteFile(page.Server.MapPath(resourcePath
+
fileName), buffer);
}
catch
(Exception err)
{
}
}
}
}
WriteFile方法的代码:
public
static
void
WriteFile(
string
fileName,
byte
[] buf)
{
FileStream f
=
File.OpenWrite(fileName);
f.Write(buf,
0
,buf.Length);
f.Close();
}
实现客户端多文本上传服务器容易产生错误的地方是客户端文件路径和服务器路径混淆不清,其他其实和简单
查看全文
相关阅读:
EasyUI 清空表格
【21年01月DW打卡】Task02
【BUG12】排查解决一个锁超时 "MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction" 的SQL问题
【20年12月DW打卡】joyful-pandas
【21年01月DW打卡】Task01
【12月DW打卡】joyful-pandas
【12月DW打卡】joyful-pandas
【Pandas】resample重采样中的周‘W’按周日开始为一周('W'的频率偏移默认为‘right’、使用label = 'left' 重设)+ 常用freq的别名/注释
【12月DW打卡】joyful-pandas
【12月DW打卡】joyful-pandas
原文地址:https://www.cnblogs.com/qingwa008/p/1173381.html
最新文章
android第四次作业
Promethues-Operator对接ldap
Ingress Nginx v0.30 Hostnetwork高性能模式安装
js实现树级递归,通过js生成tree树形菜单(递归算法)
vue 实现在文本框光标处插入内容
jquery-ui draggable中div拖动出现辅助线方便对齐,实现简单布局器
【转】jquery-ui draggable中div拖动出现辅助线方便对齐(优化)
vue-cli3.0 修改 index.html title标签中出现的htmlWebpackPlugin.options.title
mysql 按指定字符拆分字符串
js中对象数组按对象属性排序
热门文章
VS2019 设置使用 CTRL+/ 注释和取消注释
mysql 查询json
MySQL查询受影响的行数
[Vue warn]: Failed to mount component: template or render function not defined.
时序数据库入门
mongo数据导出csv文件
支付宝第三方应用取消授权
tomcat,线程调度优化
HttpClient以multipart/form-data上传文件
Jquery 重置表单
Copyright © 2011-2022 走看看