开发者

Files I upload are not going into the right folder

I thought I had my uploads working correctly on Friday, but when I tested the site this morning, it doesn't work right. My uploads are supposed to be going into an uploads/ file and then to a file that corresponds to the ProductID to which that upload is going.

Ex: My Test Product is ProductID 519. I want to upload a document so it should go to uploads/519. When I hover over the uploaded file, it says uploads/519/PhoneList.xls - which is correct. But when I check my Solution Explorer in Visual Studio 2010, the file shows up outside of the 519 file as 519PhoneList.xls

Can someone tell me why this is happening and help me figure out 开发者_如何学Chow to fix it? I've tried deleting a / here and there but I can't find the right place to fix.

 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>


Do the folder 519 exists ?

DocumentUpload.PostedFile.SaveAs(Server.MapPath("/uploads/" & ProductID.Value & DocumentUpload.PostedFile.FileName))

That line has an error, you're missing a & "/" between productid.value and postedfile.filename.


Change this line:

Server.MapPath("/uploads/" & ProductID.Value & "/" & DocumentUpload.PostedFile.FileName)

Might be easier using String.Format:

Server.MapPath(String.Format("/uploads/{0}/{1}", ProductId.Value, DocumentUpload.PostedFile.FileName))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜