我的网站上有一些ModalPopUpExtender,管理员可以将视频,文档,图像和图片上传到特定产品。上传似乎工作得很好,它显示在数据库和网站.....但是当我点击页面上的链接它说:“你正在寻找的资源可能已被删除,名称已更改,或者暂时不可用。“我的上传在哪里?
什么都没有被上传到我的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
我将try中的第一个语句替换为您的语句,但它仍然给我一个404错误。当我将鼠标悬停在列表项目上时,它看起来像已保存到文件夹中,但仍未保存。 – jlg
我的错误,我拿出整个try/catch并使用你输入的代码。我将/ path/with/uploads /替换成了它,并且工作正常。我可以在我的解决方案资源管理器中看到该文档,但我的网站希望从该产品的单个文件夹中提取。我是否必须为每个产品的上传制作文件夹,或者我可以写些东西让这个应用程序为每个产品生成一个文件夹。现在有519个产品 – jlg
哦,谢谢你的方式!我不知道要花多长时间才能在Google上找到答案:) – jlg