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();
}
实现客户端多文本上传服务器容易产生错误的地方是客户端文件路径和服务器路径混淆不清,其他其实和简单
查看全文
相关阅读:
python
C++的socket编程学习
GooglePlay
GooglePlay
Admob
cocos2dx
cocos2dx
cocos2dx
cocos2dx
浅谈白鹭Egret
原文地址:https://www.cnblogs.com/qingwa008/p/1173381.html
最新文章
基础架构系列
解决Docker安装Redis不能远程链接的问题
批量转移MySql数据表及附带脚本
SaaS化工作流引擎设计方案
Docker Swarm 常用命令
5大数据库种类,如果你全部在实际项目中用过,绝对是大神!
服务调用链的主要因素和简要对比
50+ Useful Docker Tools
docker pull提示x509错误的对应方法
一键清理 Nexus 中无用的 Docker 镜像
热门文章
微服务架构之spring cloud zipkin
微服务架构之spring boot admin
微服务架构之spring cloud turbine
微服务架构之spring cloud gateway
微服务架构之spring cloud hystrix&hystrix dashboard
微服务架构之spring cloud feign
微服务架构之spring cloud ribbon
微服务架构之spring cloud eureka
微服务架构之spring cloud 介绍
Excel导出插件-VSTO
Copyright © 2011-2022 走看看