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();
}
实现客户端多文本上传服务器容易产生错误的地方是客户端文件路径和服务器路径混淆不清,其他其实和简单
查看全文
相关阅读:
SOJ4478 Easy Problem II(模拟、栈)
SOJ4480 Easy Problem IV (并查集)
暴力枚举法总结
区间DP学习总结
51nod 1019 逆序数(逆序数+离散化)
win7系统查看硬盘序列号步骤
雷达图制作方法
matlab更改打开时候默认路径
excel多组数据散点图生成
EndNote(三)之中文引文导入方式
原文地址:https://www.cnblogs.com/qingwa008/p/1173381.html
最新文章
不同字符串,HashCode可能相同
高并发之CAS机制和ABA问题
Oracle 简单统计示例
设计模式的六大原则
BeanNameAware和BeanFactoryAware接口
Spring Bean的生命周期
Linux colrm命令详解
select大表报错
Linux col命令详解
Linux updatedb命令详解
热门文章
Linux read命令详解
Linux scp命令详解
Linux whereis命令详解
Linux cp命令详解
Linux which命令详解
SOJ 1002/1003/1004 大整数相加/相乘/相除
HDU 6206 Apple (高精确度+JAVA BigDecimal)
SOJ3266 Birthday
SOJ1029 Humble Numbers (枚举)
SOJ4459 skysky's game(贪心+优先队列)
Copyright © 2011-2022 走看看