【问题标题】:Apply other textbox to fileupload将其他文本框应用于文件上传
【发布时间】:2019-08-15 20:58:32
【问题描述】:

所以我自己创建了一个 ASP Web 表单,基本上使用 sql 数据库来保存上传的文件并能够再次下载它们。我使用了一个文件上传,它工作得很好。我想知道的是,无论如何我可以在其他地方获得信息,例如文档文件路径,然后将其放入 fileupload1.postedfile 等,这样我就可以从我已经为该文件上传的构建函数中上传它。

所以我自己的文件上传工作完美,使用一个简单的文件上传浏览和上传按钮,然后将它作为二进制等保存到 sql 数据库。

Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
        Dim fileExtension As String =Path.GetExtension(FileUpload1.PostedFile.FileName)
        Dim documentType As String = String.Empty


        Dim uploader As String = Environment.UserName


        'provide document type based on it's extension
        Select Case fileExtension
            Case ".pdf"
                documentType = "application/pdf"
                Exit Select
            Case ".xls"
                documentType = "application/vnd.ms-excel"
                Exit Select
            Case ".xlsx"
                documentType = "application/vnd.ms-excel"
                Exit Select
            Case ".doc"
                documentType = "application/vnd.ms-word"
                Exit Select
            Case ".docx"
                documentType = "application/vnd.ms-word"
                Exit Select
            Case ".gif"
                documentType = ".gif"
                Exit Select
            Case ".png"
                documentType = ".png"
                Exit Select
            Case ".jpg"
                documentType = ".jpg"
                Exit Select
            Case ".txt"
                documentType = ".txt"
                Exit Select
            Case ".msg"
                documentType = "application/vnd.ms-outlook"
                Exit Select
            Case ".mht"
                documentType = ".mht"
                Exit Select

        End Select

        'Calculate size of file to be uploaded
        Dim fileSize As Integer = FileUpload1.PostedFile.ContentLength



        'Create array and read the file into it
        Dim documentBinary As Byte() = New Byte(fileSize - 1) {}
        FileUpload1.PostedFile.InputStream.Read(documentBinary, 0, fileSize)

我想要这样做的目的是我会得到一个 .txt 文件,其中包含多行不同的文件路径。然后我希望能够通读该 .txt 文件(这不是问题),然后几乎让上传自动完成,我基本上可以像 uploadfile1.selectedfile = "c:\example.txt" 左右。而不是一次做一个。

请原谅我,因为我对文件上传和使用二进制字节日期等将其存储在 sql 数据库中相当陌生。

【问题讨论】:

    标签: asp.net vb.net visual-studio


    【解决方案1】:

    出于安全原因,网页无法自动启动文件上传。浏览器要求用户选择要上传的文件。

    但是有一些方法可以让文件输入控件一次上传多个文件。这比一次做1更难。

    【讨论】:

    • 但是没有真正的方法可以基本上读取一个包含文件路径的 .txt 文件并分别上传?
    • 不使用浏览器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2019-03-09
    • 2016-02-28
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    相关资源
    最近更新 更多