我认为上周五我的上传工作正常,但是当我今天早上测试网站时,它无法正常工作。我的上传应该进入上传/文件,然后进入与上传的ProductID相对应的文件。
Ex:我的测试产品是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>
答案 0 :(得分:2)
文件夹519是否存在?
DocumentUpload.PostedFile.SaveAs(Server.MapPath(“/ uploads /”&amp; ProductID.Value&amp; DocumentUpload.PostedFile.FileName))
该行有错误,你错过了&amp; productid.value和postingfile.filename之间的“/”。
答案 1 :(得分:1)
更改此行:
Server.MapPath("/uploads/" & ProductID.Value & "/" & DocumentUpload.PostedFile.FileName)
使用String.Format可能更容易:
Server.MapPath(String.Format("/uploads/{0}/{1}", ProductId.Value, DocumentUpload.PostedFile.FileName))