使用 vb.net 上传/下载文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13101546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 10:55:31  来源:igfitidea点击:

File Upload / download using vb.net

asp.netvb.netfile-upload

提问by barsan

I'm trying to develop a website with File upload and download option using vb.net and asp.net with Visual Studio 2008. Can anyone help me about how can I provide the facility of uploading a file into the server and then a download link will be available for the common users to download the file from the server. Thanks in advance.

我正在尝试使用 vb.net 和 asp.net 和 Visual Studio 2008 开发一个带有文件上传和下载选项的网站。谁能帮助我了解如何提供将文件上传到服务器然后提供下载链接的工具将可供普通用户从服务器下载文件。提前致谢。

回答by codingbiz

You can use asp:FileUploadcontrol to upload file to your server, a location with permission to write file

您可以使用asp:FileUpload控件将文件上传到您的服务器,该位置具有写入文件的权限

It's as simple as putting the control in your .aspxfile

就像将控件放在.aspx文件中一样简单

<asp:FileUpload runat="server" ID="MyFileUpload" />

Codebehind

代码隐藏

If (MyFileUpload.HasFile) Then
   MyFileUpload.SaveAs('the full path to directory ' & filename)

End If

You can store the file description in database with their path, retrieve this on your page and display to user

您可以将文件描述及其路径存储在数据库中,在您的页面上检索它并显示给用户

You can also browse your directory and list the files on your page

您还可以浏览您的目录并列出您页面上的文件

回答by Markweb

Use FileUpLoad control. Here is a sample for uploading (in c#) : http://www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx

使用 FileUpLoad 控件。这是一个上传示例(在 c# 中):http: //www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx

回答by user2693794

Dim FileToCopy As String

Dim FileToCopy 作为字符串

    FileToCopy = "F:\fd_demo_limits.swf"


    Dim filenameTest = System.IO.Path.GetFileName(FileToCopy)

    Dim path As String = "E:\"

    Dim filename As String = "communicate.png"

    Dim file_ As New System.IO.FileInfo(path + filename)

    Dim file_ContentLength As String = "900000" ' check file Length file_.Length = 833740
    If (file_.Length > file_ContentLength) Then
        MsgBox("file length is large")
        Exit Sub
    End If

    Dim allow_send_pic() As String = {".jpg", ".png", ".gif", "ico", ".png"}

    Dim Extension As String = System.IO.Path.GetExtension(filename)

    If Array.IndexOf(allow_send_pic, Extension.ToLower()) = -1 Then
        MsgBox("File extension not valid")
        Exit Sub
    End If

    If System.IO.File.Exists(FileToCopy) = True Then

        While (System.IO.File.Exists(path + filename))
            filename = "Copy of " + filename
        End While

        System.IO.File.Copy(FileToCopy, path + filename)
        MsgBox("File Copied")


    End If