zoukankan
html css js c++ java
从html页面Post附件到aspx接收页
客户端例子:
<
form
id
="fResAtt"
name
="fResAtt"
enctype
="multipart/form-data"
action
="http://bill.xxxx.net/UploadResAttService.aspx"
method
="post"
target
="_blank"
>
<
input
id
="__EVENTTARGET"
name
="__EVENTTARGET"
type
="hidden"
value
=""
/>
<
input
id
="__EVENTARGUMENT"
name
="__EVENTARGUMENT"
type
="hidden"
value
=""
/>
<
script
language
="javascript"
type
="text/javascript"
>
<!--
function
__doPostBack(eventTarget, eventArgument)
{
var
fr
=
document.getElementById('fResAtt');
if
(fr.onsubmit
==
null
||
fr.onsubmit())
{
fr.__EVENTTARGET.value
=
eventTarget;
fr.__EVENTARGUMENT.value
=
eventArgument;
fr.submit();
}
}
//
-->
</
script
>
<
input
id
="resumeID"
name
="resumeID"
type
="hidden"
value
="C212CFB7-1675-445D-8101-A593E99EE126"
/>
<
input
id
="attFile"
name
="attFile"
type
="file"
/>
<
input
id
="submitAtt"
name
="submitAtt"
type
="button"
value
="提交"
onclick
="__doPostBack('', '');"
/>
</
form
>
此hmtl页包含一下类型为file的input,此数据会被post到另一个aspx接引页,提交时定义一个__doPostBack的js函数,在函数中使form进行submit()。
接收的aspx页
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
String.IsNullOrEmpty(GetValue(
"
resumeID
"
)))
{
ResumeAttachmentConfiguration attConfig
=
JobConfiguration.GetConfig().ResumeAttachmentConfiguration;
Guid resumeID
=
new
Guid(GetValue(
"
resumeID
"
));
HttpPostedFile postedFile
=
Request.Files[
0
];
//
上传文件类型限制
bool
allowedType
=
false
;
ArrayList typeList
=
attConfig.GetAllowedAttachmentTypeList();
string
[] extensions
=
postedFile.FileName.Split(
'
.
'
);
string
fileExtension
=
extensions[extensions.Length
-
1
].ToString();
//
获取上传文件名的扩展名
foreach
(
string
attType
in
typeList)
{
if
(attType.Trim().ToLower()
==
fileExtension.ToLower())
{
allowedType
=
true
;
break
;
}
}
if
(
!
allowedType)
{
OutputErrorMessage(
"
上传的文件类型不在允许范围之内
"
);
}
//
上传文件大小限制
if
(postedFile.ContentLength
>
attConfig.MaxAttachmentSize
*
1000
)
{
OutputErrorMessage(
"
上传的附件大小超出允许范围
"
);
}
//
添加简历附件
ResumeAttachment att
=
new
ResumeAttachment(postedFile, resumeID);
try
{
ResumeAttachments.AddAttachment(att);
}
catch
(Exception ex)
{
OutputErrorMessage(ex.Message);
}
OutputSusscessMessage();
}
OutputErrorMessage(
"
请提供简历UID
"
);
}
private
string
GetValue(
string
name)
{
return
Request.Form.Get(name);
}
private
void
OutputMessage(
string
msg)
{
Response.Output.Write(msg);
Response.End();
}
private
void
OutputErrorMessage(
string
msg)
{
OutputMessage(
"
flase:
"
+
msg);
}
private
void
OutputSusscessMessage()
{
OutputMessage(
"
true:
"
+
"
成功添加了简历附件
"
);
}
HttpPostedFile postedFile
=
Request.Files[
0
];方法提取了第一个Post过来的附件。
查看全文
相关阅读:
高并发系统如何设计
PHP的垃圾回收机制(开启垃圾回收机制后的优缺点是什么)
移动端网站如何开发(电脑端网站到手机端网站我们需要在html代码中添加哪个meta标签)
家庭洗车APP --- Androidclient开展 之 网络框架包介绍(一)
一天JavaScript示例-判定web页面的区域
左右margin top问题百分比值
Ubuntu14.04设备JDK
三层架构,四大天王——删
MEMO:UIButton 中的图片和标题 左对齐
HDU 3874 离线段树
原文地址:https://www.cnblogs.com/chenjunbiao/p/1760251.html
最新文章
How to allow/block PING on Linux server – IPTables rules for icmp---reference
Step-by-Step XML Free Spring MVC 3 Configuration--reference
Spring Security Hello World Example--reference
使用hql当异常查询:Xxx is not mapped[from Xxx where ...]
有关Struts2a的ction直接使用response异步问题
.ARM.exidx
Thread thread2 = new Thread()
hdoj1010Starship Troopers (树dp,依赖背包)
MTK MOTA升级步骤
C#基础之二
热门文章
第一章 工欲善其事 其利润—Android SDK工具(2)
前框 (一个)zTree 从数据库树形菜单动态加载
超过lua上帝的语言
memcache课程---3、php使用memcache缓存实例
memcache课程---2、php如何操作memcache
memcache课程---1、memcache介绍及安装(memcache作用)
php数据结构课程---6、常见排序有哪些
php数据结构课程---5、树(树的 存储方式 有哪些)
lavarel中如何使用memcache
laravel中如何使用Redis(Redis是什么)
Copyright © 2011-2022 走看看