2010-12-18 70 views
1

好吧,我在domain1工作。我需要将文件上传到domain2。在我DOMAIN1 ASPX我有(外主):如何将文件上传到另一个aspx文件?

<div id="divCurriculo"> 
    <form id="frmCurric" enctype="multipart/form-data" action="http://reports.programacontactosonae.com/uploadcv.aspx" method="post"> 
     <input type="hidden" name="userid" value="284" /> 
    <table> 
     <tr> 

      <td class="first"> 
       <label>Currículo</label> 
      </td> 
      <td> 
       <input type="file" id="filecv" style="display:inline-block;" /> 
       <input type="submit" value="Enviar" style="width:70px;display:inline-block;" /> 
      </td>  
     <tr>    
    </table> 

    </form> 
</div> 

所以,我需要什么,我接收文件中域2来获取文件?这是我有:

protected void Page_Load(object sender, EventArgs e) 
{ 
     string userid = Request.Form["userid"]; 
     Response.Write(userid + "<br />"); // i catch, successfully, the value in the hiddenfield 

     HttpPostedFile file = Request.Files[0];//here i get an error cause it can't find any file 
     Response.Write(file.ToString());    
} 
+1

根据您的评论如下;请在这两个页面上发布您正在使用的*实际*代码,并分享您要将此表单输入的页面的种类。 – 2010-12-18 19:02:44

+0

如果您有应该工作的enctype;怎么了? – 2010-12-18 19:07:28

+0

当我访问Request.Files [0]我得到的索引超出了数组的边界,因为没有文件 – 2010-12-18 19:18:47

回答

2

希望它的东西,这很简单,但尝试添加enctype="multipart/form-data"form标签:

<form action="www.domain2.com/upload.aspx" method="post" enctype="multipart/form-data"> 
    <input type="hiden" id="userid" value="12345" /> 
    <input type="file" id="curriculo" /> 
    <input type="submit" id="submit"/> 
</form> 
+0

哦,谢谢你,我很抱歉。我正在使用enctype,我忘了将它放在我的问题中... – 2010-12-18 18:59:03

+0

请粘贴您正在使用的*实际*代码...我们还能如何帮助您? – 2010-12-18 19:01:19

1

看起来你只是缺少ENCTYPE;在对 ,添加一个属性:

<form ... enctype="multipart/form-data">... 
+0

谢谢你,我很抱歉。我正在使用enctype,我只是忘了把它放在我的问题.. – 2010-12-18 19:09:26

2

除了关于失踪enctype属性其他的答案,你的代码是很脆,否则;在尝试访问Request.Files集合之前,应检查并确保至少有一个文件存在,并在文件不存在时显示错误消息,让他们知道再试一次。否则,忘记选择文件的用户将得到一个非常无益的错误信息(您现在看到的错误信息相同)

否则,我会假设/希望您正在验证/清理安全方面的东西 - 比如不信任提交的用户标识值,并验证提交的内容是否危险。

+0

谢谢,我是。我只是把简化版本的代码放在这里。我正在使用enctype,我只是忘了把它放在这里。 – 2010-12-18 19:09:05

相关问题