금요일에 올바르게 업로드 한 것으로 알고 있었지만 오늘 아침에 사이트를 테스트했을 때 제대로 작동하지 않습니다. 내 업로드는 업로드/파일로 이동 한 다음 해당 업로드가 진행되는 ProductID에 해당하는 파일로 이동합니다.업로드 한 파일이 올바른 폴더에 들어 있지 않습니다.
예 : 내 테스트 제품은 ProductID 519입니다. 문서를 업로드하여 업로드/519해야합니다. 업로드 된 파일 위로 마우스를 가져 가면 업로드/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>
방법 :
쉽게 사용 및 String.format 수 있습니다. SQL 인젝션에 대해 읽어야합니다. – David
감사합니다. @ 데이비드, 알겠습니다. – jlg