我認爲我的上傳在星期五正常工作,但是當我今天上午測試網站時,它無法正常工作。我的上傳應該會進入上傳/文件,然後進入與上傳的產品ID相對應的文件。我上傳的文件沒有進入正確的文件夾
例如:我的測試產品是ProductID 519.我想上傳一個文檔,以便上傳/ 519。當我將鼠標懸停在上傳的文件上時,它顯示uploads/519/PhoneList.xls - 這是正確的。但是,當我在Visual Studio 2010中檢查我的解決方案資源管理器時,文件顯示在519文件之外,因爲519PhoneList.xls
有人可以告訴我爲什麼會發生這種情況,並幫助我弄清楚如何解決它?我試過刪除一個/這裏和那裏,但我找不到合適的地方修復。
Protected Sub SubmitDocument_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitDocument.Click
DocumentModal.Hide()
'Builds the full absolute URL to be inserted into the database.
Dim hostURL As String = Request.Url.Scheme & "://" & Request.Url.Host & ":" & Request.Url.Port & Request.ApplicationPath
Dim sqlFileHREF As String = Nothing
Dim MarketingTitle As String = DocumentTitle.Text
'SQL INSERT: Marketing Table
sqlFileHREF = "INSERT INTO Marketing (ProductID, MarketingTypeID, MarketingTitle, MarketingData) VALUES (" & ProductID.Value & " ,4, '" & DocumentTitle.Text & "', '" & hostURL & "uploads/" & ProductID.Value & "/" & DocumentUpload.FileName & "')"
sqlFileHREF.Replace("'", "''")
DocumentUpload.PostedFile.SaveAs(Server.MapPath("/uploads/" & ProductID.Value & DocumentUpload.PostedFile.FileName))
'Create SQL Connection
Dim SqlConnection As New SqlConnection("Server=off-db1;uid=productsDB_admin;pwd=*****;database=Products")
SqlConnection.Open()
Dim sqlCommand As New SqlCommand(sqlFileHREF, SqlConnection)
sqlCommand.ExecuteNonQuery()
SqlConnection.Close()
Response.Redirect(Request.RawUrl)
End Sub
<!-- Add a Document -->
<li>
<asp:LinkButton ID="DocumentButton" runat="server">Document</asp:LinkButton>
<asp:Panel ID="DocumentPanel" runat="server" CssClass="modalPopup" Style="display:none">
Title:<asp:TextBox ID="DocumentTitle" runat="server"></asp:TextBox>
<asp:FileUpload ID="DocumentUpload" runat="server" />
<asp:Label ID="DocumentLabel" runat="server"></asp:Label>
<asp:Button ID="SubmitDocument" runat="server" Text="Upload" onclick="SubmitDocument_Click" /><asp:Button ID="CancelDocument" runat="server" Text="Cancel" /><asp:HiddenField ID="filename" runat="server" />
</asp:Panel>
<asp:ModalPopupExtender ID="DocumentModal" runat="server" DropShadow="True" DynamicServicePath="" Enabled="True" PopupControlID="DocumentPanel" TargetControlID="DocumentButton"></asp:ModalPopupExtender>
</li>
你插入的數據是危險的方式。你應該閱讀關於SQL注入。 – David
謝謝@David,我會的。 – jlg