从html页面Post附件到aspx接收页

客户端例子:

None.gif      < form  id ="fResAtt"  name ="fResAtt"  enctype ="multipart/form-data"  action ="http://bill.xxxx.net/UploadResAttService.aspx"  method ="post"  target ="_blank" >
None.gif        
< input  id ="__EVENTTARGET"  name ="__EVENTTARGET"  type ="hidden"  value =""   />  
None.gif        
< input  id ="__EVENTARGUMENT"  name ="__EVENTARGUMENT"  type ="hidden"  value =""   />
ExpandedBlockStart.gifContractedBlock.gif        
< script  language ="javascript"  type ="text/javascript" > dot.gif
InBlock.gif            
<!--
InBlock.gif            
function __doPostBack(eventTarget, eventArgument) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
var fr = document.getElementById('fResAtt');
InBlock.gif                
if (fr.onsubmit == null || fr.onsubmit()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    fr.__EVENTTARGET.value 
= eventTarget; 
InBlock.gif                    fr.__EVENTARGUMENT.value 
= eventArgument; 
InBlock.gif                    
InBlock.gif                    fr.submit(); 
ExpandedSubBlockEnd.gif                }
 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//-->
ExpandedBlockEnd.gif
        
</ script >
None.gif        
None.gif        
< input  id ="resumeID"  name ="resumeID"  type ="hidden"  value ="C212CFB7-1675-445D-8101-A593E99EE126"   />
None.gif        
< input  id ="attFile"  name ="attFile"  type ="file"   />
None.gif        
< input  id ="submitAtt"  name ="submitAtt"  type ="button"  value ="提交"  onclick ="__doPostBack('', '');"   />
None.gif    
</ form >

此hmtl页包含一下类型为file的input,此数据会被post到另一个aspx接引页,提交时定义一个__doPostBack的js函数,在函数中使form进行submit()。

接收的aspx页
None.gif      protected   void  Page_Load( object  sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {    
InBlock.gif        
if (!String.IsNullOrEmpty(GetValue("resumeID")))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ResumeAttachmentConfiguration attConfig 
= JobConfiguration.GetConfig().ResumeAttachmentConfiguration;
InBlock.gif            Guid resumeID 
= new Guid(GetValue("resumeID"));
InBlock.gif
InBlock.gif            HttpPostedFile postedFile 
= Request.Files[0];
InBlock.gif
InBlock.gif            
//上传文件类型限制
InBlock.gif
            bool allowedType = false;
InBlock.gif            ArrayList typeList 
= attConfig.GetAllowedAttachmentTypeList();
InBlock.gif
InBlock.gif            
string[] extensions = postedFile.FileName.Split('.');
InBlock.gif            
string fileExtension = extensions[extensions.Length - 1].ToString();//获取上传文件名的扩展名
InBlock.gif

InBlock.gif            
foreach (string attType in typeList)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (attType.Trim().ToLower() == fileExtension.ToLower())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    allowedType 
= true;
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (!allowedType)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                OutputErrorMessage(
"上传的文件类型不在允许范围之内");
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
// 上传文件大小限制
InBlock.gif
            if (postedFile.ContentLength > attConfig.MaxAttachmentSize * 1000)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                OutputErrorMessage(
"上传的附件大小超出允许范围");
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//添加简历附件
InBlock.gif
            ResumeAttachment att = new ResumeAttachment(postedFile, resumeID);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ResumeAttachments.AddAttachment(att);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                OutputErrorMessage(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            OutputSusscessMessage();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        OutputErrorMessage(
"请提供简历UID");
ExpandedBlockEnd.gif    }

None.gif
None.gif    
private   string  GetValue( string  name)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
return Request.Form.Get(name);
ExpandedBlockEnd.gif    }

None.gif    
private   void  OutputMessage( string  msg)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        Response.Output.Write(msg);
InBlock.gif        Response.End();
ExpandedBlockEnd.gif    }

None.gif    
private   void  OutputErrorMessage( string  msg)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        OutputMessage(
"flase:" + msg);
ExpandedBlockEnd.gif    }

None.gif    
private   void  OutputSusscessMessage()
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        OutputMessage(
"true:" + "成功添加了简历附件");
ExpandedBlockEnd.gif    }

HttpPostedFile postedFile  =  Request.Files[ 0 ];方法提取了第一个Post过来的附件。

转载于:https://www.cnblogs.com/BillChen/archive/2006/05/15/400311.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值