我上传的地方在哪里?

时间:2011-08-24 20:41:56

标签: asp.net vb.net file-upload upload

我的网站上有一些ModalPopUpExtenders,管理员可以将视频,文档,图片和图片上传到特定产品。上传似乎工作得很好,它显示在数据库和网站上.....但当我点击页面上的链接时,它说“您要查找的资源可能已被删除,其名称已更改,或暂时无法使用。“

没有任何内容被上传到我的ASP.net 4.0 VB网站的实际上传文件夹中。谁能告诉我发生了什么事?

<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: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>    

    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 = "INSERT INTO Marketing (ProductID, MarketingTypeID, MarketingTitle, MarketingData) VALUES (" & ProductID.Value & " ,4, '" & DocumentTitle.Text & "', '" & hostURL & "uploads/" & ProductID.Value & "/" & DocumentUpload.FileName & "')"
    sqlFileHREF.Replace("'", "''")
    If DocumentUpload.HasFile Then
        Try
            DocumentUpload.SaveAs("uploads" & _
               DocumentUpload.FileName)
            DocumentLabel.Text = "File name: " & _
               DocumentUpload.PostedFile.FileName & "<br>" & _
               "File Size: " & _
               DocumentUpload.PostedFile.ContentLength & " kb<br>" & _
               "Content type: " & _
               DocumentUpload.PostedFile.ContentType
        Catch ex As Exception
            DocumentLabel.Text = "ERROR: " & ex.Message.ToString()
        End Try
    Else
        DocumentLabel.Text = "You have not specified a file."
    End If

    '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

3 个答案:

答案 0 :(得分:2)

您需要指定保存文件的位置:

DocumentUpload.PostedFile.SaveAs(Server.MapPath("/path/" & DocumentUpload.PostedFile.FileName))

Server.MapPath将虚拟路径映射到物理路径,这就是.SaveAs所需的。

答案 1 :(得分:1)

您尚未告知服务器保存文件的位置。请查看特定代码示例的MSDN演练:http://msdn.microsoft.com/en-us/library/aa479405.aspx

答案 2 :(得分:0)

如果未指定路径,则可能位于C:\ Windows \ System32。