Where are my uploads going?
I have some ModalPopUpExtenders on my site where admins can upload videos, documents, images, and pictures to a specific product. The upload seems to work just fine, it shows up in the database and on the site.....but when I click the link on the page it says "The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable."
Nothing is being uploaded into the actual uploads folder that is part of my ASP.net 4.0 VB site. Can anyone tell me what is going on?
<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=of开发者_JS百科f-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
You need to specify where to save the file:
DocumentUpload.PostedFile.SaveAs(Server.MapPath("/path/" & DocumentUpload.PostedFile.FileName))
Where Server.MapPath will map a virtual path to a physical path, which is what .SaveAs requires.
You haven't told the server where to save the file. Please look at the MSDN walk-through for specific code samples: http://msdn.microsoft.com/en-us/library/aa479405.aspx.
If no path is specified they are probably in C:\Windows\System32.
精彩评论