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过来的附件。
查看全文
相关阅读:
Jeesite 自定义api接口 404 访问不到页面
Eclipse中项目Project Explorer视图与Package Explorer视图
PHP linux ZendGuardLoader.so: undefined symbol: executor_globals
Linux block(1k) block(4k) 换算 gb
Gogs 部署安装(Linux)
搭建gogs常见问题
Gogs 部署安装(windows)
Long polling failed, will retry in 16 seconds. appId: zeus-guard, cluster: default, namespaces: application, long polling url: null, reason: Get config services failed from···
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
top命令详析及排查问题使用演示
原文地址:https://www.cnblogs.com/chenjunbiao/p/1760251.html
最新文章
设计模式之美:Iterator(迭代器)
设计模式之美:Interpreter(解释器)
设计模式之美:Command(命令)
设计模式之美:Chain of Responsibility(职责链)
设计模式之美:Structural Patterns(结构型模式)
设计模式之美:Proxy(代理)
设计模式之美:Flyweight(享元)
设计模式之美:Facade(外观)
使用JPA中@Query 注解实现update 操作
SpringBoot之前端文件管理
热门文章
Spring Boot 设置静态资源访问
IDEA更换主题
把mysql脚本或其他数据库脚本导入Powerdesigner
Intellij idea 项目目录设置 与包的显示创建
maven缺少依赖包,强制更新命令
Ubuntu16.04安装后开发环境配置和常用软件安装
VIM退出命令
apache 与 tomcat、PHP 关系
解决Eclipse每次修改完代码后需要先Clean,不然修改的代码无效
word 2013 题注、图注、插入图片自动修改大小、批量更新题注编号
Copyright © 2011-2022 走看看