Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 我的上传到哪里去了?_Asp.net_Vb.net_File Upload_Upload - Fatal编程技术网

Asp.net 我的上传到哪里去了?

Asp.net 我的上传到哪里去了?,asp.net,vb.net,file-upload,upload,Asp.net,Vb.net,File Upload,Upload,我的网站上有一些ModalPopupExtender,管理员可以将视频、文档、图像和图片上传到特定的产品。上传似乎工作正常,它显示在数据库和网站上……但当我单击页面上的链接时,它会说“您正在查找的资源可能已被删除、名称已更改或暂时不可用。” 没有任何内容上载到实际上载文件夹中,该文件夹是我的ASP.net 4.0 VB站点的一部分。谁能告诉我发生了什么事 <li> <asp:LinkButton ID="DocumentButton" runat="server">

我的网站上有一些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
  • 文件 标题:
  • 受保护的子提交文档\u单击(ByVal sender作为对象,ByVal e作为事件参数)处理提交文档。单击 DocumentModal.Hide() '生成要插入数据库的完整绝对URL。 Dim hostURL为String=Request.Url.Scheme&“:/”&Request.Url.Host&“:”&Request.Url.Port&Request.ApplicationPath Dim sqlFileHREF As String=“插入营销(ProductID、MarketingTypeID、MarketingTitle、MarketingData)值(“&ProductID.Value&”,4,”&DocumentTitle.Text&“,”&hostURL&“uploads/”&ProductID.Value&“/”&DocumentUpload.FileName&“)” sqlFileHREF.Replace(“'”,“'”) 如果是DocumentUpload.HasFile,则 尝试 DocumentUpload.SaveAs(“上传”和_ DocumentUpload.FileName) DocumentLabel.Text=“文件名:”&_ DocumentUpload.PostedFile.FileName&“
    ”和_ “文件大小:&”_ DocumentUpload.PostedFile.ContentLength&“kb
    ”和_ “内容类型:&”_ DocumentUpload.PostedFile.ContentType 特例 DocumentLabel.Text=“错误:”&ex.Message.ToString() 结束尝试 其他的 DocumentLabel.Text=“您尚未指定文件。” 如果结束 '创建SQL连接 Dim SqlConnection作为新的SqlConnection(“服务器=off-db1;uid=productsDB_admin;pwd=******;数据库=Products”) SqlConnection.Open() Dim sqlCommand作为新的sqlCommand(sqlFileHREF,SqlConnection) sqlCommand.ExecuteNonQuery() SqlConnection.Close() Response.Redirect(Request.RawUrl) 端接头
    您还没有告诉服务器将文件保存到哪里。有关特定代码示例,请参阅MSDN演练:。

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

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

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

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

    将代码放在何处是否重要?我试过了,但还是不起作用。我知道有时候事情必须经过处理。请检查编辑以查看我所做的操作。我没有在其中找到它们:(我将Try-to语句中的第一条语句替换为您拥有的语句,但它仍然给我一个404错误。当我将鼠标悬停在列表项上时,看起来它们已保存到文件夹中,但它仍然没有保存。我的错误是,我取出了整个Try/catch,只使用了您键入的代码。我将/path/替换为/uploads/并成功。我可以看到我的解决方案资源管理器中的e文档,除了我的站点希望从该产品的单个文件夹中提取外。我是否必须为每个产品的上载创建文件夹,或者我是否可以编写一些东西让该应用程序为每个产品生成一个文件夹。现在有519个产品哦,顺便说一句,谢谢!我不知道需要多长时间让我在谷歌上找到答案:)