1、添加引用,因为uploadify是jquery的插件所以要将jquery一并引用
<script language="javascript" src="../js/jquery.uploadify-v1.6.2/jquery-1.3.2.min.js"></script>
<script language="javascript" src="../js/jquery.uploadify-v1.6.2/jquery.uploadify.js"></script>
2、创建上传控件
<input type="file" name="uploadfile" id="uploadfiles"/>
这里的控件应该只是占位作用,因为我在用div替换了input后一样正常显示和上传
<Div id="uploadfiles" > </Div>
3、调用组件
<script language="javascript">
$("document").ready(function(){
$('#uploadfile).fileUpload ({
'uploader' : '../js/jquery.uploadify-v1.6.2/uploader.swf',
'cancelImg' : '../js/jquery.uploadify-v1.6.2/cancel.png',
'folder' : '../upload',
'script' : 'UploadHandler.ashx',
'auto' : 'false',
'fileDesc' : 'Excel数据文件',
'fileExt' : '*.xls'
});
});
</script>
4、添加上传和取消按钮
<a href="javascript:$('#excelfile').fileUploadStart();">上传文件</a>
<a href="javascript:$('#excelfile').fileUploadClearQueue();">清空队列</a>
5、服务端接收
for (int i = 0; i < context.Request.Files.Count; i++)
{
HttpPostedFile postedFile = context.Request.Files[i];
string fileName = strUploadPath + Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
postedFile.SaveAs(fileName);
}
}
问题上传文件的大小似乎受限maxRequestLength属性
需要修改web.config文件里<httpRuntime> 元素的maxRequestLength属性,maxRequestLength属性的单位为KB
浙公网安备 33010602011771号