2011-11-25 74 views
0

,所以我在網頁上做了2件事情時遇到了一個小問題。我正在使用a將文件上傳到我的Web服務器,同時我還有其他用於從用戶獲取數據的名稱(名字,姓氏等)表單是runat = server,應該上傳的按鈕該文件(在初步檢查文件是否正常並且表單字段被正確填寫之後)也是runat服務器,並且具有onserver點擊。上傳文件並同時提交表單,使用vb

主要問題是,當我給表單一個「get」方法時,我可以得到想要的結果,讓我的所有數據都在我想要的url中,但是我無法上傳文件。雖然如果我刪除該標籤,我可以上傳文件,但是我的網址中沒有數據。

(相關代碼)

<script language="VB" runat="server"> 
     Dim str As String 
     Sub Button1_Click(ByVal Source As Object, ByVal e As EventArgs) 

      'Dim submitFunction As String = "<script type='text/javascript'> function submitform() { document.myform.submit();}" & "</" & "script>" 
      Session("firstTime") = 4 
      Session("errCheck") = 1 
      If InputF.Value = "" Then 
       Span1.InnerHtml = "Error: you must enter a file name" 
       Return 
      End If 

      If Not (InputF.PostedFile Is Nothing) Then 
       Try 
        If Session("firstTime") <> 1 Then 

         If Request.QueryString("fName") = "" Then 
          str += "Please Enter your first name <br/>" 
          Session("errCheck") += 1 
         End If 
         If Request.QueryString("lName") = "" Then 
          str += "Please Enter your last name <br />" 
          Session("errCheck") += 1 
         End If 
         If Request.QueryString("addr1") = "" Then 
          str += "Please Enter your address <br />" 
          Session("errCheck") += 1 
         End If 
         If Request.QueryString("city") = "" Then 
          str += "Please Enter a city name <br />" 
          Session("errCheck") += 1 
         End If 
         If Len(Request.QueryString("prov")) <> 2 Then 
          str += "Please Enter a 2 character province <br />" 
          Session("errCheck") += 1 
         End If 
         If Len(Request.QueryString("pCode")) <> 6 Then 
          str += "Please Enter a valid postal code <br />" 
          Session("errCheck") += 1 
         End If 
         If Request.QueryString("hPhone") = "" Then 
          str += "Please Enter your home phone <br />" 
          Session("errCheck") += 1 
         ElseIf Len(Request.QueryString("hPhone")) <> 10 Then 
          str += "Please enter a 10 digit number for your home phone <br />" 
          Session("errCheck") += 1 
         End If 
        End If 
        If Session("errCheck") = 1 Then 
         InputF.PostedFile.SaveAs(("FILE PATH TO MY SERVER" & Request.QueryString("compName") & " - " & Request.QueryString("fName") & ", " & Request.QueryString("lName") & InputF.Value)) 
         'Response.Redirect("default.aspx?fName=" & Request.QueryString("fName")) 
        End If 

       Catch exc As Exception 
        str += "Error Saving File" 
        Span1.InnerHtml = "Error saving file" 
        Session("errCheck") += 1 
       End Try 

      End If 

     End Sub 'Button1_Click 

</script> 


        <form name="myform" id="myform" method="get" runat="server" enctype="multipart/form-data"> 
        <table> 
         <h2><% If Session("errCheck") <> 1 Then 
            Response.Write(Str) 
           End If%></h2> 
         <tr> 
          <td align="right"><label>Resume/Documents</label></td> 
          <td><input type="file" runat="server" id="InputF" name="InputF" onchange="handleFiles(this.files)" /><input type="button" id="adder" value="add another document" onclick="addInput('dynamicInput');" /></td> 
          <div id="dynamicInput"> 
          </div> 
         </tr> 
         <tr> 
          <td>     
           <span id=Span1 
           style="font: 8pt verdana;" 
           runat="server" /> 
          </td> 
         </tr> 
        <input type="hidden" id="Hidden13" name="compName" value="<% response.Write(request.QueryString("compName")) %>" /> 
        <input type="hidden" id="posCode" name="posCode" value="<% response.Write(request.QueryString("posCode"))%>" /> 
        <input type="hidden" id="reqNum" name="reqNum" value="<% response.Write(request.QueryString("reqNum")) %>" /> 
        <input type="hidden" id="company" name="company" value="<% response.Write(request.QueryString("company"))%>" /> 
        <input type="hidden" id="division" name="division" value="<% response.Write(request.QueryString("division")) %>" /> 
        <input type="hidden" id="department" name="department" value="<% response.Write(request.QueryString("department"))%>" /> 
         <tr> 
          <td align="right">First name<span style="color:Red;">*</span>:</td> 
          <td><input type='text' name='fName' id='fName' size='50' maxlength="50"value="<% Response.Write(Request.QueryString("fName"))%>" /></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Last name </label><span style="color:Red;">*</span>:</td> 
          <td><input type='text' name='lName' id='lName' size='50' maxlength="50" value="<% response.Write(request.QueryString("lName"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Initial</label>:</td> 
          <td><input type='text' name='init' id='init' size='2' maxlength="2" value="<% response.Write(request.QueryString("init"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Email</label>:</td> 
          <td><input type='text' name='email' id='email' size='50' maxlength="50" value="<% response.Write(request.QueryString("email"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Address 1</label><span style="color:Red;">*</span>:</td> 
          <td><input type='text' name='addr1' id='addr1' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr1"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Address 2</label>:</td> 
          <td><input type='text' name='addr2' id='addr2' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr2"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>City</label><span style="color:Red;">*</span>:</td> 
          <td><input type='text' name='city' id='city' size='25' maxlength="25" value="<% response.Write(request.QueryString("city"))%>"/></td> 
         </tr> 
         <br /> 
         <tr> 
          <td align="right"><label>Province</label><span style="color:Red;">*</span>:</td> 
          <td><input type='text' name='prov' id='prov' size='2' maxlength="2" value="<% response.Write(request.QueryString("prov"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Country</label>:</td> 
          <td><input type='text' name='count' id='count' size='25' maxlength="25" value="<% response.Write(request.QueryString("count"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Postal code</label><span style="color:Red;">*</span>:</td> 
          <td><input type='text' name='pCode' id='pCode' size='25' maxlength="25" value="<% response.Write(request.QueryString("pCode"))%>"/></td> 
         </tr> 
         <tr> 
          <td align="right"><label>Home Phone</label><span style="color:Red;">*</span>:</td> 
          <td><input type='text' name='hPhone' id='hPhone' size='15' maxlength="15" value="<% response.Write(request.QueryString("hPhone"))%>"/></td> 
          <p>Format for phone numbers: Areacode, phone number, no spaces, no dashes ie: 2041231234</P> 
         </tr> 
         <tr> 
          <td align="right"><label>Work Phone</label>:</td> 
          <td><input type='text' name='wPhone' id='wPhone' size='25' maxlength="25" value="<% response.Write(request.QueryString("wPhone"))%>"/></td> 
         </tr> 
        </table> 
          <input type=button 
          id="Button1" 
          value="Submit Application" 
          OnServerClick="Button1_Click" 
          runat="server" /> 
       </form> 

回答

0

我很接近得到這自己。在表單提交時,我會對其他文件進行所有驗證,如果全部驗出,我將表單提交到其他頁面(以及其他不相關的代碼)。

基本上我發佈的代碼是好的,我只是缺少了一些東西時,它提交

簡而言之爲:

'if there are no errors with the user feilds 
If Session("errCheck") = 1 Then 
        Try 
        If Not (System.IO.Path.GetFileName(InputF.PostedFile.FileName.ToString()) Is Nothing) Then 
         Try 
          InputF.PostedFile.SaveAs(("somepath:\somepath\somepath\somepath\" & Trim(Request.Form("compName")) & " - " & Request.Form("lName") & ", " & Request.Form("fName") & "-" & System.IO.Path.GetFileName(InputF.PostedFile.FileName.ToString()))) 
         Catch ex As Exception 
          Session("errCheck") += 1 
          str += "Error Saving File" & ex.Message 
         End Try 
If Session("errCheck") = 1 Then 
         Response.Redirect("final2.aspx?fName=" & Request.Form("fName") & "&lName=" & Request.Form("lName") & "&compName=" & Trim(Request.Form("compName")) & 
         "&posCode=" & Request.Form("posCode") & "&reqNum=" & Request.Form("reqNum") & "&company=" & Request.Form("company") & 
         "&division=" & Request.Form("division") & "&department=" & Request.Form("department") & "&init=" & Request.Form("init") & 
         "&email=" & Request.Form("email") & "&addr1=" & Trim(Request.Form("addr1")) & "&addr2=" & Request.Form("addr2") & 
         "&city=" & Request.Form("city") & "&prov=" & Request.Form("prov") & "&count=" & Request.Form("count") & 
         "&pCode=" & Request.Form("pCode") & "&hPhone=" & Request.Form("hPhone") & "&wPhone=" & Request.Form("wPhone")) 
        End If 

希望這是有道理的人看着我的問題,現在我的回答。

相關問題