110,536
社区成员
发帖
与我相关
我的任务
分享
public void UploadFile()
{
//本地电脑文件路径
FileStream stream = new FileStream(@"C:\Users\li\Desktop\tb.txt", FileMode.Open, FileAccess.Read);
int size = Convert.ToInt32(stream.Length);
Byte[] bytes = new Byte[size];
stream.Read(bytes, 0, size);
stream.Close();
FileStream fos = null;
//上传到远程服务器
string filePath = Server.MapPath("~/DataFile/");
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string fileName = "111.txt";
fos = new FileStream(filePath + fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fos.Write(bytes, 0, bytes.Length);
fos.Close();
}
<div id="divUpload"></div>
<script type="text/javascript" language="javascript">
var fileMgr = new HttpUploaderMgr();
fileMgr.Config["PostUrl"] = "http://localhost:4854/asp.net/upload.aspx";
$(function ()
{
fileMgr.loadTo("divUpload");
$("#btnPost").click(function ()
{
fileMgr.postAll();
});
//上传本地文件
$("#btnPostLoc").click(function ()
{
fileMgr.app.addFile({ path: "D:\\QQ2013.exe" } );
});
});
</script>
单文件整合代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>单文件上传示例</title>
<link href="js/up2.css" type="text/css" rel="Stylesheet"/>
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/json2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/up2-single.js" type="text/javascript" charset="utf-8"></script>
<script language="javascript" type="text/javascript">
var fileMgr = new HttpUploaderMgr();
fileMgr.event.postComplete = function (obj) { };
fileMgr.event.postError = function (obj) { };
fileMgr.event.postProcess = function (obj, speed, postedLength, percent, times) { };
$(document).ready(function ()
{
fileMgr.loadAuto();
//上传用户选择的文件
$("#btnSel").click(function ()
{
fileMgr.postAuto("upPnl"); //
});
//上传指定路径中的文件
$("#btnPostLoc").click(function ()
{
fileMgr.postLoc("D:\\360safe-inst.exe", "upPnl"); //
});
});
</script>
</head>
<body>
<p>此页面演示单个文件上传样式</p>
<div id="upPnl"></div>
<input id="btnSel" type="button" value="浏览" />
<input id="btnPostLoc" type="button" value="上传本地文件" />
</body>
</html>
示例下载:
exe安装包
cab安装包(x86)
cab安装包(x64)
开发文档
ASP示例
ASP.NET示例
JSP示例
PHP示例
<div id="divUpload"></div>
<script type="text/javascript" language="javascript">
var fileMgr = new HttpUploaderMgr();
fileMgr.Config["PostUrl"] = "http://localhost:4854/asp.net/upload.aspx";
$(function ()
{
fileMgr.loadTo("divUpload");
$("#btnPost").click(function ()
{
fileMgr.postAll();
});
//上传本地文件
$("#btnPostLoc").click(function ()
{
fileMgr.app.addFile({ path: "D:\\QQ2013.exe" } );
});
});
</script>
单文件整合代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>单文件上传示例</title>
<link href="js/up2.css" type="text/css" rel="Stylesheet"/>
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/json2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/up2-single.js" type="text/javascript" charset="utf-8"></script>
<script language="javascript" type="text/javascript">
var fileMgr = new HttpUploaderMgr();
fileMgr.event.postComplete = function (obj) { };
fileMgr.event.postError = function (obj) { };
fileMgr.event.postProcess = function (obj, speed, postedLength, percent, times) { };
$(document).ready(function ()
{
fileMgr.loadAuto();
//上传用户选择的文件
$("#btnSel").click(function ()
{
fileMgr.postAuto("upPnl"); //
});
//上传指定路径中的文件
$("#btnPostLoc").click(function ()
{
fileMgr.postLoc("D:\\360safe-inst.exe", "upPnl"); //
});
});
</script>
</head>
<body>
<p>此页面演示单个文件上传样式</p>
<div id="upPnl"></div>
<input id="btnSel" type="button" value="浏览" />
<input id="btnPostLoc" type="button" value="上传本地文件" />
</body>
</html>
示例下载:
exe安装包
cab安装包(x86)
cab安装包(x64)
开发文档
ASP示例
ASP.NET示例
JSP示例
PHP示例
[/quote]
晚上我下载来试试,不行再说 var web = new WebClient();
web.UploadFile("http://localhost:1234/mysite/xxxx.aspx", "c:\\abc\1.txt");
这可以一目了然地是知道,是”传“文件了。虽然还是自己传给自己,但是这就具有技术深度、真正适配的”传“这个字眼儿。
所以我就是这个意思,用字眼儿的方式不同,背后是动手进行技术测试的出发点和测试标准确实不同。<input type=file .....>
这类标签,总之是有它的原则、规矩、出处、承载的客户端软件。你设计的程序不在这个范围内,所以白费了许多精力而并不在正确的设计范围内。