简体   繁体   中英

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. Thanks in advance.

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

It's as simple as putting the control in your .aspx file

<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. Here is a sample for uploading (in c#) : http://www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx

Dim FileToCopy As String

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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