简体   繁体   English

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

[英]File Upload / download using vb.net

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. 我正在尝试使用vb.net和asp.net在Visual Studio 2008中开发一个具有文件上载和下载选项的网站。有人可以帮助我如何提供将文件上载到服务器然后下载链接的功能吗?可供普通用户从服务器下载文件。 Thanks in advance. 提前致谢。

You can use asp:FileUpload control 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 .aspx file 就像将控件放入您的.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 您还可以浏览目录并在页面上列出文件

Use FileUpLoad control. 使用FileUpLoad控件。 Here is a sample for uploading (in c#) : http://www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx 这是一个上传示例(在c#中): http : //www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx

Dim FileToCopy As String 昏暗的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM